From simon.urbanek at r-project.org  Tue Sep 24 00:34:14 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 24 Sep 2013 00:34:14 +0200
Subject: [Rd] Capture output of install.packages (pipe system2)
In-Reply-To: <5240A280.1000804@gmail.com>
References: <CABFfbXtWhc48KviWCQXR84xGywm1GU0oMWk1Vk7s0EqbcAfT5g@mail.gmail.com>
	<5240A280.1000804@gmail.com>
Message-ID: <F165061B-F2DF-47CF-898F-920DC27C0DF7@r-project.org>

Duncan,

On Sep 23, 2013, at 10:20 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

> On 13-09-23 2:17 PM, Jeroen Ooms wrote:
>> Is there any way to capture output (both stdout and stderr) from
>> install.packages? Solutions like sink and capture.output don't work
>> because the install.packages calls out to system2 which is executed in
>> a separate process:
>> 
>>     test <- capture.output(install.packages("MASS"))
>> 
>> The system2 function does have arguments stdout and stderr but afaik
>> these cannot be controlled via install.packages. I'm a bit reluctant
>> to start rolling my own version of install.packages just for this
>> reason.
>> 
>> Is there any way to somehow grab this output? Or alternatively, is
>> there a way to make R pipe stdout and stderr from system2 in such a
>> way that they can be captured with sink or capture.output in the R
>> parent process?
> 
> See the recent thread <https://mailman.stat.ethz.ch/pipermail/r-devel/2013-September/067552.html> for an approach to this.
> 

Can you, please, elaborate on how it is that relevant? The linked thread is talking about sink() which it irrelevant here (to quote the original e-mail "Solutions like sink and capture.output don't work because the install.packages calls out to system2 which is executed in a separate process:"). Something I missed?

Re original question: there is keep_outputs which allows to re-direct a copy of the output into a file - at least for the actual install part of it. 
On top of my head for full capture I can only think of custom C code that will re-direct stderr/out FDs as desired (it's really trivial to re-direct to files, for dynamic capture it's a little more involved but there are examples that do that).

Cheers,
Simon



[Rd] Capture output of install.packages (pipe system2)
Simon Urbanek