Rscript in silent mode

averageman picture averageman · Aug 5, 2014 · Viewed 8.2k times · Source

I am using Rscript to run an R script but I get a lot of output on my screen. Can I run Rscript in silent mode (meaning without any screen output)?

Answer

Dirk Eddelbuettel picture Dirk Eddelbuettel · Aug 5, 2014

Several options come to mind:

  1. within R: use sink() to divert output to a file, see help(sink)

  2. on the shell: Rscript myscript.R 2>&1 >/dev/null

  3. edit the code :)

  4. on Linux, use our littler frontend as it runs in --slave mode by default :)

Options 3 is the most involved but possibly best. You could use a logging scheme where you print / display in "debug" or "verbose" but not otherwise. I often do that, based on a command-line toggle given to the script.