1

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
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
maloneypatr
  • 3,562
  • 4
  • 23
  • 33
  • 1
    Just a thought, is your task set to run with the right username and permissions? – Hong Ooi Jun 10 '13 at 12:30
  • 2
    Please, don't modify the original question without advice; otherwise the answers that refer to a modified part of the original question seems nonsense... :-( – Aacini Jun 10 '13 at 16:14
  • @Aacini - Sorry about that. Still a noob! Thanks for the heads up though and be sure not to do that again. – maloneypatr Jun 10 '13 at 20:36
  • @Hong - Yep, I do have admin rights. I'm the only one who uses the computer and 'Me' is the only username. Thanks for the idea though! – maloneypatr Jun 10 '13 at 20:38

1 Answers1

2

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
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
  • Thanks for the advice! I edited the .bat file according to your suggestions and I get the same results. If I doubleclick on the .bat file, it runs and creates the csv. When I run this through Task Scheduler, it does not create the csv while the 'Last Run' column has been updated. Any other thoughts on what I might be doing wrong? Thanks again! – maloneypatr Jun 10 '13 at 11:57
  • @maloneypatr ummm, no, not off-hand. That does seem a bit odd. I'll have a think. – Simon O'Hanlon Jun 10 '13 at 12:01