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
4
  • 1
    Just a thought, is your task set to run with the right username and permissions? Commented Jun 10, 2013 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... :-( Commented Jun 10, 2013 at 16:14
  • @Aacini - Sorry about that. Still a noob! Thanks for the heads up though and be sure not to do that again. Commented Jun 10, 2013 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! Commented Jun 10, 2013 at 20:38

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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 ummm, no, not off-hand. That does seem a bit odd. I'll have a think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.