Reputation: 3622
I run a report in R every morning and I'm trying to automate this task. I have a Windows machine and I've created a task within Task Scheduler. I can get the file to run at a certain time, but I can't get it to export the csv. My initial thoughts is that there is a disconnect between forward- & back-slashes, but I'm not sure where the break is. Anyone have any thoughts?
R_script.R
setwd('C:/Users/Me/Desktop')
x <- runif(5)
y <- runif(5)
xy <- data.frame(X = x, Y = y)
write.csv(xy, 'C:/Users/Me/Desktop/xy.csv')
Batch File
Rscript CMD BATCH
C:\Users\Me\R_script.R
Upvotes: 1
Views: 2071
Reputation: 59990
Try running the first line of your batch file in a cmd
window. It results in an error:
>Rscript CMD BATCH
Fatal error: cannot open file 'CMD': No such file or directory
And if you use R CMD BATCH
it doesn't detect the input file because they should be on the same line:
>R CMD BATCH
no input file
Instead run the command in one of these two ways, with the file path on the same line:
>Rscript C:\Users\Me\R_script.R
>R CMD BATCH C:\Users\Me\R_script.R
Upvotes: 2