From mtmorgan at fhcrc.org  Wed Oct  5 18:59:39 2011
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Wed, 05 Oct 2011 09:59:39 -0700
Subject: [Rd] suppressing stderr output from system() calls
In-Reply-To: <972B666A-E4F0-4479-9C45-13428A5AD0B7@garvan.org.au>
References: <972B666A-E4F0-4479-9C45-13428A5AD0B7@garvan.org.au>
Message-ID: <4E8C8CFB.60107@fhcrc.org>

On 10/05/2011 02:36 AM, Mark Cowley wrote:
> Dear list,

> I'm trying to suppress/redirect/squash the output from commands like
> install.packages, or download.file. The problem is that none of:
> sink(..., type="message"), sink(..., type="output"), capture.output,
> suppressMessages are quite doing the trick. Output gets written to
> the stderr stream, despite any combination of the above suppression
> commands.

Hi Mark --

For download.file, the argument quiet=TRUE suppresses output messages; 
this option can be used in ... for install.packages, too (according to 
the documentation). This is good enough to quieten the regular chatter 
on a successful operation. To catch errors and suppress warnings also, 
maybe a construct like

url = "http://r-project.org/doesnotexist"
tryCatch(suppressWarnings(
     capture.output(download.file(url, tempfile(), quiet=TRUE))),
     error=function(...) {})

Martin

> According to ?sink:
> Messages sent to ?stderr()? (including those from ?message?, ?warning? and ?stop?) can be diverted by ?sink(type = "message")? (see below).
>
> I'm pretty sure it's the system(), or .Internal() calls which are the culprit, which currently write the majority (all?) of their output to the stderr stream.
>
> Simple example:
> con<- file("stderr.txt", "w")
> sink(con, type="message")
> system("ls")
> sink(NULL, type="message")
> close(con)
> # instead of the output going to stderr.txt, it gets printed to the console.
>
> # no good either
> capture.output(system("ls"))
> character(0)
>
> This is an issue, since i'm writing GenePattern modules to run R code, and if anything is written to stderr, then the job gets hit with a 'job failed' status, when all that might have happened is an R package got installed, or a file got downloaded via FTP.
>
> Any ideas? Can system() and .Internal() output be redirected to stdout?
>
> cheers,
> Mark
>
>
> sessionInfo()
> R version 2.13.1 (2011-07-08)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>
>
>
> -----------------------------------------------------
> Mark Cowley, PhD
>
> Pancreatic Cancer Program | Peter Wills Bioinformatics Centre
> Garvan Institute of Medical Research, Sydney, Australia
> -----------------------------------------------------
>
>
> 	[[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



[Rd] suppressing stderr output from system() calls
Martin Morgan