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)?
In a newer version of R, Rscript or Rscript. exe is a command mode of R without a terminal and can be used as a shell script. It also provides a more convenient interface than traditional ways as SHELL> R --vanilla < a_rscript. r.
On Mac/Linux, the Rscript path is typically /usr/local/bin/Rscript or /usr/bin/Rscript . On Windows, the path for R version X.Y.Z is typically C:/Program Files/R/R-X. Y.Z/bin/Rscript.exe . If you don't specify a path, rscript will try to find the Rscript executable on its own by searching commonly used paths.
Several options come to mind:
within R: use sink()
to divert output to a file, see help(sink)
on the shell: Rscript myscript.R 2>&1 >/dev/null
edit the code :)
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.
You can redirect the output with
Rscript myscript.R >& >/dev/null (linux)
or
Rscript myscript.R >$null (windows)
or use R
directly:
R --quiet --vanilla < myscript.R
or
R CMD BATCH myscript.R
(That last version writes the output to a file myscript.Rout
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With