125

I'm struggling with the different R executables. What is the difference between R.exe (with or without CMD BATCH option), Rcmd.exe, Rscript.exe and Rterm.exe when running command line in a batch file?

And what is the difference between:

R.exe --no-environ --no-save < "c:\temp\R\test.R" > "c:\temp\R\out.txt" 2>&1

and

R.exe CMD BATCH --no-environ --no-save "c:\temp\R\test.R" "c:\temp\R\out.txt"

No difference in the output.

I cannot find anything about Rcmd.exe and Rscript.exe in the 3079 pages R reference manual.

By the way: I am using Windows.

AndrewGB
  • 16,126
  • 5
  • 18
  • 49
waanders
  • 8,907
  • 22
  • 70
  • 102
  • 6
    How about [R Introduction - Invoking R from the command line](http://cran.r-project.org/doc/manuals/R-intro.html#Invoking-R-from-the-command-line)? And [two section later - scripting with R](http://cran.r-project.org/doc/manuals/R-intro.html#Scripting-with-R). – Marek Aug 05 '10 at 09:09
  • 3
    Yes, I've read that. But no word about Rcmd.exe and just a few lines about Rscript.exe. help(Rscript) gives me some more information – waanders Aug 05 '10 at 14:00
  • $R CMD BATCH test.R out.Rout – kamran kausar Oct 25 '22 at 13:51

1 Answers1

128

Caveat: I work much more on Linux than Windows:

  • Rcmd.exe is a historical left-over as back in the day, you could not do R CMD something on Windows but needed the special executable Rcmd.exe something. That is no longer the case, yet it is provided for backwards compatibility.
  • Rterm.exe is also a holdover from the days when Rcmd.exe was used. Can be ignored these days.
  • R CMD BATCH is a crutch that was needed in the days before littler and Rscript.exe, and similarly lingering from old docs and habits..
  • Rscript.exe is your friend for batch scripts; use it.
  • For everything else, there's R.exe.

Other than that, as Marek hinted, the reference manual is the wrong one among the six available manuals. Try the Introduction to R and the Installation and Admin manuals both of which have specific appendices for Windows.

Community
  • 1
  • 1
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks. So I can forget Rcmd.exe and R CMD BATCH? – waanders Aug 05 '10 at 14:01
  • 1
    I just want to run a R script with command line agurments in a Windows (shell) batchfile. As I understand it correctly R.exe is enough for me. – waanders Aug 05 '10 at 14:03
  • R Introduction states "Within a terminal window (...) invoking by R.exe or more directly by Rterm.exe". So for everything else Rterm? – Marek Aug 05 '10 at 14:11
  • 1
    Sorry, forgot about `Rterm.exe`. Also a leftover. – Dirk Eddelbuettel Aug 05 '10 at 14:14
  • Remarkable: When I start R.exe with a R script by using a batchfile I see a R.exe process AND a Rterm.exe process running in the Windows Task Manager – waanders Aug 10 '10 at 06:53
  • 7
    There is an important difference between R.exe and Rterm.exe - Rterm.exe is compiled with /LARGEADDRESSAWARE and can allocate 4 GB RAM when run under Windows 64 bit, unlike R.exe (we're talking about 32 bit R running under 64 bit Windows). Why would the R people do this only for Rterm.exe and not for R.exe, if Rterm.exe is obsolete? – Meh Oct 14 '10 at 12:46
  • I can't know why they did it. I know sometimes the smaller package is also faster. – EngrStudent Oct 02 '15 at 17:15
  • 3
    ... also an important difference between R and Rscript in that Rscript does not load `package:methods` ... and that is part of why it is your friend for batch scripts (faster start up time) : https://stackoverflow.com/questions/19680462/rscript-does-not-load-methods-package-r-does-why-and-what-are-the-consequen – russellpierce Nov 03 '17 at 01:11
  • And I demonstrated repeatedly that `r` starts faster than `Rscript` -- while *also* loading package `methods`. – Dirk Eddelbuettel Nov 03 '17 at 04:26
  • 1
    The advice given here should be in the R and RStudio documentation. `Rscript.exe` is your friend for batch scripts; use it. For everything else, there's `R.exe`. The R and RStudio documentation is not very helpful for Windows users. R and RStudio are still very much written for the Unix / Linux / Mac OSX community. They need to point out up front what are the leftovers in the Windows R and RStudio distros from ancient Unix and DOS days. – Rich Lysakowski PhD Jan 22 '20 at 22:45
  • Thanks for that lovely explanation. Does anyone know what purpose Rgui.exe serves? Calling it from VBA seems to open the R GUI (outside of RStudio), but doesn't run the desired R script. – pseudorandom Aug 11 '23 at 18:11