[R] Rscript: how to suppress all output

johannes rara johannesraja at gmail.com
Sun Jan 3 10:29:01 CET 2010


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>:
> On Sat, 2 Jan 2010, johannes rara wrote:
>
>> How can I suppress ALL output when running Rscript in Terminal?
>>
>> ~/Documents>Rscript test.r
>
> 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().
>
>> I tried options --slave, --vanilla with no success. I get these
>
> --slave is the default for Rscript: use Rscript --verbose to see what it is
> doing (see ?Rscript).
>
>> Loading required package: methods
>> ..etc..
>
> (That one is because you did not specify methods as part of the initial
> package list: see ?Rscript.)
>
>> and other output as well.
>>
>> -J
>>
>>> sessionInfo()
>>
>> 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
>>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>



More information about the R-help mailing list