[R] R CMD BATCH *without* saving output

Henrik Bengtsson hb at biostat.ucsf.edu
Thu Jul 24 22:10:36 CEST 2014


On *nix like systems:
Rscript myscript.R > /dev/null 2>&1

On Windows:
Rscript myscript.R > NUL 2>&1

The above sends both standard output ("1") and standard error ("2") to nirvana.

I prefer using 'Rscript', but the same works with any command
including 'R CMD BATCH'.

/Henrik

PS. Bill, capture.output() would more or less hang your R session for
such large outputs (here "50 GB and counting"), cf.
http://www.jottr.org/2014/05/captureOutput.html

On Thu, Jul 24, 2014 at 7:42 PM, William Dunlap <wdunlap at tibco.com> wrote:
> You also might try wrapping the call to the scripts with capture.output().
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Thu, Jul 24, 2014 at 9:54 AM, Nick Matzke <matzke at berkeley.edu> wrote:
>> Actually, this was the full solution:
>>
>> At the beginning of the script:
>>
>> # Suppressing all output/warnings/try errors:
>> # Open connection to black hole
>> con=file(open="/dev/null")
>> # Don't print anything to screen
>> sink(file=con, type="output")
>> # Don't print messages (e.g. errors/warnings)
>> sink(file=con, type="message")
>>
>>
>> At the end of the script:
>>
>> # Turn off output sink
>> sink()
>> # Turn off message sink
>> sink(type="message")
>> # Close connection to black hole
>> close(con)
>>
>>
>>
>>
>> On Thu, Jul 24, 2014 at 12:27 PM, Nick Matzke <matzke at berkeley.edu> wrote:
>>
>>>
>>> On Thu, Jul 24, 2014 at 12:16 PM, Nick Matzke <matzke at nimbios.org> wrote:
>>>
>>>> Hi all,
>>>>
>>>> Hi have a series of scripts that print a lot of notes etc. to screen.  I
>>>> have to run them on a massive set of input files. The scripts are
>>>> self-contained and save the important output to data files in an organized
>>>> way.  I don't need the screen output for anything.
>>>>
>>>> Problems:
>>>>
>>>> - If I run the script from the R command line, the output printed to
>>>> Terminal got so huge that it crashed Terminal (I was running 10 of these at
>>>> once)
>>>>
>>>>  - I tried R CMD BATCH, but this just created .Rout files that are size
>>>> 50 GB and counting.
>>>>
>>>> I suppose I could be a grownup and refactor all my code with print
>>>> options that I can turn off, but I would rather be lazy.
>>>>
>>>> So, is there a way to run R CMD BATCH or something similar, and NOT print
>>>> the output to screen or to the .Rout file?
>>>>
>>>> I tried:
>>>>
>>>> R CMD BATCH --no-save , but that still seems to save the the screen
>>>> output etc. to .Rout.
>>>>
>>>> Thanks,
>>>> Nick
>>>>
>>>
>>>
>>> Here is one likely solution to the above question (also, I am now sending
>>> from the email address that is subscribed to R-help):
>>>
>>> Put:
>>> sink("/dev/null")
>>>
>>> ...at the beginning of the script. All screen output now goes to the black
>>> hole of /dev/null and is not saved.
>>>
>>> At the end of the script, put
>>> sink()
>>>
>>> ...to turn this behavior off.
>>>
>>> (Tip courtesy of Brian O'Meara)
>>>
>>> There may be even easier solutions, if so, I'm still interested, since I
>>> couldn't find anything obvious googling R CMD BATCH (although this function
>>> seems to have many options not listed in the help for R CMD BATCH).
>>>
>>> Thanks,
>>> Nick
>>>
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>
> ______________________________________________
> 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.



More information about the R-help mailing list