[R] Automating R script with Windows 7

FJ M chicagobrownblue at hotmail.com
Mon Mar 5 18:56:01 CET 2012


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.  		 	   		  


More information about the R-help mailing list