[R] cat() to STDERR

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Apr 20 19:25:01 CEST 2007


Prof Brian Ripley wrote:
> On Fri, 20 Apr 2007, Peter Dalgaard wrote:
>
>   
>> ivo welch wrote:
>>     
>>> Dear R wizards---I read Brian Ripley's post from 2004 which said that
>>> it was not possible to print to STDERR.  Alas, I have more modest
>>> needs.  I was wondering if it was possible to just send a string to
>>> STDERR with cat() while in CMD BATCH mode.
>>>
>>> Is it not possible to open STDERR in R?  (Or does R use STDERR for
>>> itself and redirect it into the output stream?)
>>>
>>> This would be on a standard Unix (gentoo) system and R 2.4.x.
>>>
>>>
>>>       
>> $ echo 'sink(stderr());cat("Goodbye, cruel World!\n");sink()' | R -q
>> --vanilla 2> tictactoe
>>     
>>> sink(stderr());cat("Goodbye, cruel World!\n");sink()
>>>       
>> $ cat tictactoe
>> Goodbye, cruel World!
>>     
>
> Is there a reason not to simply use
>
> cat("Goodbye, cruel World!\n", file = stderr())
>
> here?  (Of course, stderr() is not necessarily STDERR, but in a Linux 
> terminal it is.)
>
>   
Of course not... Just me forgetting that cat() has a file argument.



More information about the R-help mailing list