[R] "displayed" output of cat(..., stderr()) is garbaged

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Sat Jun 15 08:57:32 CEST 2002


On Fri, 14 Jun 2002, Vadim Ogranovich wrote:

> Dear R-users,
>
> To display progress of a loop I wanted to print the current value of the
> loop variable, e.g.
>
> > for (i in 1:2) cat("i=", i, "\n")
> for (i in 1:2) cat(i, "\n")
> i= 1
> i= 2
>
>
> So far so good. Now I want to redirect it to stderr() (to make it
> unbuffered)
>
> > for (i in 1:2) cat("i=", i, "\n", stderr())
> for (i in 1:2) cat("i=", i, "\n", stderr())
> i= 1
>  2i= 2
>  2>
>
> This is contaminated with the value of the stderr file descriptor (2).
>
> Is there any way to get rid of this "garbage"? Is there any other way to
> write to stderr?

Use it as documented:

cat("i=", i, "\n", file=stderr())


-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list