Why (or when) is Rscript (or littler) better than R CMD BATCH?

Carlos Cinelli picture Carlos Cinelli · Feb 23, 2014 · Viewed 12.9k times · Source

I am automating some webscraping with R in cron and sometimes I use R CMD BATCH and sometimes I use Rscript.

To decide which one to use I mainly focus if I want the .Rout file or not.

But reading the answers to some questions here in SO (like this or this) it seems that Rscript is preferred to R CMD BATCH.

So my questions are:

  • Besides the fact that the syntax is a little different and R CMD BATCH saves an .Rout file while Rscript does not, what are the main differences between the two of them?

  • When should I prefer one over another? More specifically, in the cron job above mentioned, is one of them preferred?

  • I have not used yet littler, how is it different from both Rscript and R CMD BATCH?

Answer

Karl Forner picture Karl Forner · Mar 12, 2014

From what I understand:

R CMD BATCH:

  • echo the input statements
  • can not output to stdout

Rscript:

  • does NOT echo
  • output to stdout
  • can be used in one-liner (i.e. with no input file)

littler:

  • all that Rscript does
  • can read commands from stdin (useful for pipelining)
  • faster startup time
  • load the methods package