4

I'm a novice when it comes anything outside of coding for R. I've looked up many similar posts but they aren't detailed enough as I'm unfamiliar with many of the terms.

I have a simple R script that's saved on the C: drive. I want it to run from a .bat file for now, which I will later use in the task scheduler to run automatically everyday once it's working.

I saw many posts pointed to this link.

The link mentions the working directory but then never mentions anything it again. How does windows command know the folder of the .R script if it's never seems to be entered? Right now I've changed the working directory:

cd C:\Program Files\R\R-3.0.1\bin\x64

I don't know where to go from there.

Edit: I'm running windows 7

1 Answer 1

5

On Linux:

R CMD BATCH [options] my_script.R [outfile]

On Microsoft Windows (adjust the path to R.exe as needed):

"C:\Program Files\R\R-2.13.1\bin\R.exe" CMD BATCH 
   --vanilla --slave "c:\my projects\my_script.R"

From here.

5
  • 1
    This works, thanks! I had read that CMD BATCH wasn't being used in favor of Rscript.exe as noted here: stackoverflow.com/questions/3506007/…
    – John M.
    Commented Nov 12, 2013 at 16:23
  • So this works in the command line, how would I transfer to a .bat file? I know how to create a .bat file, just don't know what to put in it.
    – John M.
    Commented Nov 12, 2013 at 16:34
  • Take a look at this question: stackoverflow.com/questions/17811871/…
    – americo
    Commented Nov 12, 2013 at 17:08
  • In order to run Rscript you need your scrip to be not interactive, take a look at this to get an idea: statmethods.net/interface/io.html
    – americo
    Commented Nov 12, 2013 at 17:20
  • Does anyone know how to run CMD BATCH to call a project using renv? I've seen this done using RScript.exe, but not with CMD BATCH. Commented Dec 21, 2020 at 22:56

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