I'm not an expert with Windows and generally try to stick to Unix-like systems for things like this, but I have found that using programs non-interactively (e.g. via .bat
files) is usually less error-prone when you add the appropriate directories to your (user) PATH
variable, rather than cd
ing into the directory and calling the executable from within the .bat
file. For example, among other things, my user PATH
variable contains C:\PROGRA~1\R\R-3.0\bin\;
- the directory that contains both R.exe
and Rscript.exe
- (where PROGRA~1
is an alias for Program Files
which you can use in an unquoted file path, since there are no spaces in the name).
After you do this, you can check that your PATH
modification was successful by typing Rscript
in a new Command Prompt - it should print out usage information for Rscript
rather than the typical xxx is not recognized as an internal or external command...
error message.
In the directory C:\Users\russe_000\Desktop\Tempfiles
, I created test_r_script.r
, which contains
library(methods)
setwd("C:\Users\russe_000\Desktop\Tempfiles")
file.create("mycsv.csv")
and test_r.bat
, which contains
Rscript --vanilla --no-save "C:\Users\russe_000\Desktop\Tempfiles\test_r_script.r"
Clicking on the Windows Batch File test_r
ran the process successfully and produced mycsv.csv
in the correct folder.
Before running test_r.bat
:

After running test_r.bat
:

I've never worked with a Windows server, but I don't see why the process would be fundamentally different than on a personal computer; you just may need your sysadmin to modify the PATH
variable if you don't have sufficient privileges to alter environment variables.