I have a 'cat' function within a for loop.
I would like it to print out the result everytime it goes through the
for loop so that I can monitor the progress, but it only prints out
(execute the cat function) once at the very end of the for loop.
A simple example:
for(i in 1:100000){
cat(i, '\n')
}
What should I do in order for the cat function to be executed
everytime it goes thorough the for loop?
Thanks!
Tatsuki Koyama wrote:> I have a 'cat' function within a for loop. > I would like it to print out the result everytime it goes through the > for loop so that I can monitor the progress, but it only prints out > (execute the cat function) once at the very end of the for loop. > A simple example: > > for(i in 1:100000){ > cat(i, '\n') > } > > What should I do in order for the cat function to be executed > everytime it goes thorough the for loop? > Thanks! >You haven't told us what operating system you're using. But I bet it's Windows and what you're seeing is the buffered output. If that's the case see the Windows FAQ 6.3. http://cran.r-project.org/bin/windows/rw-FAQ.html --sundar
Tatsuki Koyama wrote:> I have a 'cat' function within a for loop. > I would like it to print out the result everytime it goes through the > for loop so that I can monitor the progress, but it only prints out > (execute the cat function) once at the very end of the for loop. > A simple example: > > for(i in 1:100000){ > cat(i, '\n') > } > > What should I do in order for the cat function to be executed > everytime it goes thorough the for loop?This is a FAQ mentioned in the R for Windows FAQ! Please read it before posting (and do not forget to mention on which OS you are working with which version of R). Uwe Ligges> Thanks! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Just press Ctrl+W (it controls buffered output) if you are using the
RGui.
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Tatsuki Koyama" <Tatsuki.Koyama at Vanderbilt.edu>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, October 05, 2004 4:48 PM
Subject: [R] cat function within a loop
>I have a 'cat' function within a for loop.
> I would like it to print out the result everytime it goes through
> the
> for loop so that I can monitor the progress, but it only prints out
> (execute the cat function) once at the very end of the for loop.
> A simple example:
>
> for(i in 1:100000){
> cat(i, '\n')
> }
>
> What should I do in order for the cat function to be executed
> everytime it goes thorough the for loop?
> Thanks!
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
If perchance you are using Windows (and specifically Rgui) and not telling us (as the posting guide asks you to), do read the rw-FAQ Q6.3 (as the posting guide also asks you to). On Tue, 5 Oct 2004, Tatsuki Koyama wrote:> I have a 'cat' function within a for loop. > I would like it to print out the result everytime it goes through the > for loop so that I can monitor the progress, but it only prints out > (execute the cat function) once at the very end of the for loop.Have you evidence for that or are you speculating? When I run your example I get a line for every i. If you do not, something is wrong with your (unspecified) installation of R.> A simple example: > > for(i in 1:100000){ > cat(i, '\n') > } > > What should I do in order for the cat function to be executed > everytime it goes thorough the for loop?> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- 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