Skip to content

cat function within a loop

5 messages · Tatsuki Koyama, Sundar Dorai-Raj, Uwe Ligges +2 more

#
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:

            
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:

            
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
#
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
#
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:

            
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.