[R] Suppressing output (e.g. from cat)

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 24 14:11:54 CEST 2008


On Tue, 24 Jun 2008, hadley wickham wrote:

> On Tue, Jun 24, 2008 at 1:15 PM, Prof Brian Ripley
> <ripley at stats.ox.ac.uk> wrote:
>> On Tue, 24 Jun 2008, Richard Pearson wrote:
>>
>>> Wacek, many thanks! I'm wondering however whether this will be problematic
>>> on Windows (I have no windows box to hand to check this, but am creating a
>>> package that I would like to be cross-platform)?
>>
>> It will fail.  But
>>
>> sink(tempfile())
>> ...
>> sink()
>>
>> is portable (and sink("nul:") works on Windows only).
>
> Or:
>
> tc <- textConnection(NULL, "w")
> sink(tc)
> ...
> sink()
> close(tc)

That is a lot more expensive and subject to

     o	Use of textConnection(NULL, mode="w") could segfault.

(NEWS for 2.7.1).  Output textConnections are convenient, but have quite a 
lot of overhead since they need to keep the character vector current.

>
> Or
>
> capture.output(...)

Again, expensive.

> Hadley
>
> -- 
> http://had.co.nz/
>

-- 
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