[R-SIG-Mac] flushing of stdout

Joerg van den Hoff j.van_den_hoff at fzd.de
Thu Aug 23 10:24:16 CEST 2007


On Wed, Aug 22, 2007 at 02:52:55PM -0400, Simon Urbanek wrote:
> Joerg,
> 
> On Aug 22, 2007, at 11:20 AM, Joerg van den Hoff wrote:
> 
> >I post this here, since maybe it's only a Mac problem.
> >
> >
> >I noted only now an apparent change of behaviour in 2.5.0 relative
> >to older times:
> >
> 
> I'm not aware of any such change. For me the output is still shown  
> progressively, e.g.:
> 
> for (i in 1:10) { cat("foo",i,"\n"); rnorm(1e7); }
> 
> Can you, please, send us a reproducible example?
> 
> 
> >I use `cat' to stdout from within a long running loop to report
> >the loop count to the user. this output is now delayed until the  
> >program
> >completes (i.e. the output is buffered) and, thus, does not make  
> >much sense
> >anymore...
> >
> >issuing `flush(stdout())' after the `cat' does not help.
> >
> 
> .. and it's not meant to (since the R console has nothing to do with  
> stdout) - try flush.console() instead ...
> 
yeah,  sorry for being inprecise: I'm actually using R frequently
in a terminal/xterm. 

in the R GUI console flush.console() (as also proposed by kevin
middleton: many thanks) actually achieves the desired flushing (without
it: same thing)

so the problem persists in the terminal/xterm. try, e.g.,


for (i in 1:10) {
   for (j in 1:20000) log(j)
   cat(i, " ")
   flush(stdout())
}
cat("\n")


to see the effect. this only occurs if the first `cat' does not contain a
newline (I use this in situations with a large outer loop count to inform the
user how much the simulation run has progressed and it's simply nicer without
too many newlines). 

the behaviour was definitely different in older versions of R.


regards,

joerg



More information about the R-SIG-Mac mailing list