Skip to content

Rscript: how to suppress all output

4 messages · Gabor Grothendieck, Brian Ripley, johannes rara

#
How can I suppress ALL output when running Rscript in Terminal?

~/Documents>Rscript test.r

I tried options --slave, --vanilla with no success. I get these

Loading required package: methods
..etc..

and other output as well.

-J
R version 2.9.2 (2009-08-24)
i386-apple-darwin8.11.1

locale:
fi_FI.UTF-8/fi_FI.UTF-8/C/C/fi_FI.UTF-8/fi_FI.UTF-8

attached base packages:
[1] grid      splines   stats     graphics  grDevices utils
datasets  methods   base

other attached packages:
[1] ggplot2_0.8.3   reshape_0.8.3   plyr_0.1.9      proto_0.3-8
Hmisc_3.7-0     survival_2.35-7

loaded via a namespace (and not attached):
[1] cluster_1.12.1  lattice_0.17-26
#
Try this on Windows:

Rscript test.r 1>NUL 2>NUL
On Sat, Jan 2, 2010 at 3:27 PM, johannes rara <johannesraja at gmail.com> wrote:
#
On Sat, 2 Jan 2010, johannes rara wrote:

            
Rscript test.r >& /dev/null

or equivalent in your shell.  But note that Rscript produces no 
output itself:

tystie% touch test.r
tystie% Rscript test.r
tystie%

so anything you see is created by your script.  If your script 
produces output you do not want, the problem lies in your script. 
Depending how it is doing it, consider functions like invisible(), 
sink() and suppressMessages().
--slave is the default for Rscript: use Rscript --verbose to see what 
it is doing (see ?Rscript).
(That one is because you did not specify methods as part of the 
initial package list: see ?Rscript.)

  
    
#
Thanks! I'm using Mac 10.6.2. This did it:

~/Documents > cat test.r
#! /usr/bin/Rscript --vanilla --default-packages=utils

suppressMessages(require(Hmisc))
suppressMessages(require(gsubfn))

a <- 1:100
print(a)
~/Documents > Rscript test.r > /dev/null
~/Documents >

-J

2010/1/3 Prof Brian Ripley <ripley at stats.ox.ac.uk>: