Follow-up Q Re: [R] displaying computation outputs inside "for" loops

Dave Atkins datkins at
Mon Aug 9 18:51:27 CEST 2004

I have now been enlightened via Windows FAQ 6.2 on "When using Rgui the output 
to the console seems to be delayed."  Ctrl-W toggles whether console output is 

[As a side note: Damn!  I was hoping to avoid that response (i.e., having my 
ignorance pointed out), but all my searches of R-help and FAQs had focused on 
"for()" and "iteration," which didn't find the right answer.  Knowing the 
"right" question to ask goes a long way...]

Thanks, Dave

Prof Brian Ripley wrote:

> On Mon, 9 Aug 2004, Dave Atkins wrote:
>>I have a somewhat related question.  A while back I was doing some simulations 
>>using for() loops, and I wanted to keep track of the iterations using a line of 
>>code quite similar to what Dimitris presented below.  Instead of printing the 
>>iteration message at the end of each iteration (actually, at the end of every 
>>100th), nothing was printed until the for() loop was complete, and *then* all 
>>the iteration messages were reported.  Extending Dimitris' example:
>>for(i in 1:10000){
>>   x <- rnorm(5)
>>   cat("the values of `x' are:", format(x), "\n")
>>   cat("computation", i, "finished\n\n")
>>demonstrates what I'm referring to (using R v1.9.1 with Windows XP): Iterations 
>>are not printed as they occur, only at the end of the for() loop computation.
> This *is* in the rw-FAQ.  Please see the posting guide.
>>An interesting wrinkle is that I sometimes use Emacs (and ESS).  Running the 
>>code from within Emacs prints the iterations as they occur; also, if I switch to 
>>other programs and then back to R, iterations have been printed.

More information about the R-help mailing list