1

I am trying to schedule an R code execution. I was referrig Scheduling R Script and I am creating the following batch file:

C:\R\R-2.10.1\bin\Rcmd.exe BATCH D:\mydocuments\mycode.R

However, when I run the .bat file, a black command window shows up for a second and nothing else is happening. I was also trying to use Rscript.exe instead of Rcmd.exe, but that did not help.

Have you got any suggestions?

Here is the code:

r <- matrix(rnorm(100,1,1), ncol=10, nrow=10)
write.csv(r, file = "D:/aa/ttt.csv", row.names = F)

What I get after running the .bat file is the workspace and .Rout file, but this contains only a log of the code that was ran.

enter image description here

13
  • 1
    See statmethods.net/interface/batch.html
    – amwill04
    Commented Jan 18, 2016 at 21:21
  • 1
    What do you expect to happen? "black command window shows up for a second" should be exactly what you should be expecting in this case. Commented Jan 18, 2016 at 21:34
  • 1
    Post the R code. We can't know where your output would be if we can't see the script.
    – RLH
    Commented Jan 18, 2016 at 21:50
  • 1
    Can you append 'pause' on the line after the call to R so that the window does not disappear and post a screenshot? Commented Jan 18, 2016 at 22:03
  • 1
    Can you try substituting 'write.csv(r, file = "D:/aa/ttt.csv", row.names = F)' with 'write.csv(r, file = file.path("D:", "aa" , "ttt.csv"), row.names = F)' or if the bat file is located in D:\aa - simply use ' 'write.csv(r, file = "ttt.csv", row.names = F)'? Commented Jan 18, 2016 at 22:18

1 Answer 1

2

Try substituting write.csv(r, file = "D:/aa/ttt.csv", row.names = F) with write.csv(r, file = file.path("D:", "aa" , "ttt.csv"), row.names = F).

If the bat file is located in D:\aa - simply use write.csv(r, file = "ttt.csv", row.names = F)

1
  • I really appreciate your help!
    – marco11
    Commented Jan 18, 2016 at 22:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.