Hi R-users, I am trying to automate the daily running of a simple R script from Windows 7.>From previous posts, I understand that this needs to be done with the taskscheduler. I can schedule my laptop to automatically open R at a certain time, but not to execute a script. Secondary question: how do I save a list of R commands so that they get executed once the file is open? Right now, I save my code in a notepad doc and paste over in R, but there has to be another way. I have tried saving my code as .r file using the editor and open the file with R later but this does not seem to execute the code. I very much appreciate the help. Vincent Deluard, CFA -- View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4446693.html Sent from the R help mailing list archive at Nabble.com.
You are looking to run R in batch mode see How to run R in batch mode [1] and the Quick-R on Batch Processing [2] [1] http://turing.une.edu.au/~stat356/Rbatch.html [2] http://www.statmethods.net/interface/batch.html On Mon, Mar 5, 2012 at 8:55 AM, vincent.deluard <vincentdeluardr@gmail.com>wrote:> > Hi R-users, > > I am trying to automate the daily running of a simple R script from Windows > 7. > >From previous posts, I understand that this needs to be done with the task > scheduler. > I can schedule my laptop to automatically open R at a certain time, but not > to execute a script. > > Secondary question: how do I save a list of R commands so that they get > executed once the file is open? > Right now, I save my code in a notepad doc and paste over in R, but there > has to be another way. I have tried saving my code as .r file using the > editor and open the file with R later but this does not seem to execute the > code. > > I very much appreciate the help. > > Vincent Deluard, CFA > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4446693.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
I created a txt file with R commands in it and then a batch file to process the txt file. The batch file could be scheduled. The batch file is: REM on Microsoft Windows (adjust the path to R.exe as needed) "C:\Program Files\R\R-2.13.2\bin\x64\R.exe" CMD BATCH "C:\Users\Frank\Documents\R\Scripts\Multi_Graph.txt" "C:\Users\Frank\Documents\R\Scripts\Multi_Graph.out" PAUSE The text file is: x <- seq(-4, 4, length=100) hx <- dnorm(x) degf <- c(1, 3, 8, 30) colors <- c("red", "blue", "darkgreen", "gold", "black") labels <- c("df=1", "df=3", "df=8", "df=30", "normal") pdf("C:\\Users\\Frank\\Documents\\R\\Scripts\\Norm_Graph.pdf") plot(x, hx, type="l", lty=2, xlab="x value", ylab="Density", main="Comparison of t Distributions") for (i in 1:4){ lines(x, dt(x,degf[i]), lwd=2, col=colors[i]) } legend("topright", inset=.05, title="Distributions", labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors) This produces a nice plot. Frank ---------------------------------------- > Date: Mon, 5 Mar 2012 08:55:44 -0800 > From: vincentdeluardr at gmail.com > To: r-help at r-project.org > Subject: [R] Automating R script with Windows 7 > > > Hi R-users, > > I am trying to automate the daily running of a simple R script from Windows > 7. > >From previous posts, I understand that this needs to be done with the task > scheduler. > I can schedule my laptop to automatically open R at a certain time, but not > to execute a script. > > Secondary question: how do I save a list of R commands so that they get > executed once the file is open? > Right now, I save my code in a notepad doc and paste over in R, but there > has to be another way. I have tried saving my code as .r file using the > editor and open the file with R later but this does not seem to execute the > code. > > I very much appreciate the help. > > Vincent Deluard, CFA > > > -- > View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4446693.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Just save your R script as a plain text file. Here is a copy of a file that I will show you how to execute; it is saved as \temp\test.r cat('this is my R script executing\n', format(Sys.Date())) Here is the command that I execute at the 'CMD' prompt and that you would have scheduled by Windows: C:\R-2.14.2\bin\i386\Rscript.exe \temp\test.r This has the full path name (on my machine) to the 'Rscript.exe' program included in R for executing scripts Here is the output from the execution on the command prompt screen:>C:\R-2.14.2\bin\i386\Rscript.exe \temp\test.rthis is my R script executing 2012-03-05 So it is easy to setup. Let me know if you have any problems. On Mon, Mar 5, 2012 at 11:55 AM, vincent.deluard <vincentdeluardr at gmail.com> wrote:> > Hi R-users, > > I am trying to automate the daily running of a simple R script from Windows > 7. > >From previous posts, I understand that this needs to be done with the task > scheduler. > I can schedule my laptop to automatically open R at a certain time, but not > to execute a script. > > Secondary question: how do I save a list of R commands so that they get > executed once the file is open? > Right now, I save my code in a notepad doc and paste over in R, but there > has to be another way. I have tried saving my code as .r file using the > editor and open the file with R later but this does not seem to execute the > code. > > I very much appreciate the help. > > Vincent Deluard, CFA > > > -- > View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4446693.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
"vincent.deluard" <vincentdeluardr at gmail.com> writes:> I am trying to automate the daily running of a simple R script from Windows > 7. >>From previous posts, I understand that this needs to be done with the task > scheduler.That is correct.> I can schedule my laptop to automatically open R at a certain time, but not > to execute a script.For example you can use schtasks /create /tn "My R task" /sc DAILY /ST 03:00:00 /TR C:\path_to_your_batch_file.cmd to start task daily at 3am.> Secondary question: how do I save a list of R commands so that they get > executed once the file is open?I highly recommend to read a manual on Rscript and use it in your batch file instead of the "source"-ing mentioned below.> Right now, I save my code in a notepad doc and paste over in R, but there > has to be another way.Consider using some IDE. If not Emacs+ESS or Eclipse, then at least Tinn-R.> I have tried saving my code as .r file using the > editor and open the file with R later but this does not seem to execute the > code.You should "source" your file to "execute" it, i.e. source("path_to_my.R") -- Mikhail
Sounds like operating system troubles, not R troubles. If you want help with invoking R, please take a deep breath, read the FAQs and the posting guide, and tell us exactly what you did at the command line if you still think R is the problem. Note that any problems you may be having with the access permissions that your interactive or automatically-triggered environment is restricted by are almost impossible for us to remotely troubleshoot, and are not on-topic for this mailing list. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. maviney <mviney89 at hotmail.com> wrote:>hi > >i have tried all day in getting this to work, but i have fail > >I cant even schedule it to open up rscript, even by manually i cant >open >rscript > >Pls help > >-- >View this message in context: >http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4635237.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
In R you should slashes instead of backslashes: C:\PROGRA~1\R\R-2.11.1\bin\RScript.exe C:/Users/Vincent/Documents/temp/test.r Bart -- View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4635260.html Sent from the R help mailing list archive at Nabble.com.
Thank you for your help So i have tried many ways on different computers, but i believe i have an operating system, as I open RScript up in my local directory it just flashes at me and them disappears I tried to task schedule, using the following code "C:\Program Files\R\R-2.12.1\bin\i386\Rscript.exe" but the Rscript just flashes at me Thanks for ur assistance, its back to researching my problem -- View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4635275.html Sent from the R help mailing list archive at Nabble.com.
I would try first without the task scheduler: Make a .bat file and run this from the command line. This way you can see what is going on without the flashing window that is opened and closed immeadiately. maviney wrote> > > I tried to task schedule, using the following code > > "C:\Program Files\R\R-2.12.1\bin\i386\Rscript.exe" > > but the Rscript just flashes at me > > Thanks for ur assistance, its back to researching my problem >-- View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4635380.html Sent from the R help mailing list archive at Nabble.com.