How to run R in Batch mode

To run R in batch mode on Linux, assuming that xyz.r is your R source file, type the following command at the Linux console:

R --vanilla <xyz.r> xyz.out

where xyz.out is your specified R output file.

To run R in batch mode on Windows, at the working directory say c:\stat356, you have to create a batch file R.bat with the following single line (assuming the file Rterm.exe is in the directory c:\Program Files\R\rw1080\bin):

C:\progra~1\R\rw1080\bin\Rterm --vanilla

You only have to do this once. Now, assuming that your R source file is xyz.r, type the following command at the DOS Windows prompt:

R <xyz.r> xyz.out

where xyz.out is your specified R output file.

If your R source code produces graphic files and your want these files to be channeled to a particular file say xyz.ps instead of the default Rplots.ps, put

postcript("xyz.ps")

as the first line of your source file and

dev.off()

at the last line of your source file. If you want a resulting pdf file instead of the standard postcript file, use pdf("xyz.pdf") instead of postcript("xyz.ps") as the first line of your source file.