Skip to content
Prev 96410 / 398500 Next

Progress in a loop

On Wed, 2006-07-19 at 16:12 +0200, Florent Bresson wrote:
Windows I assume - you are asked to provide some rudimentary information
about your system when asking for help as the posting guide states.

You need to use flush.console() on Windows, as in:

dat <- matrix(runif(20), ncol = 2)
res <- numeric(length = 10)
for(i in 1:10) {
   res[i] <- sum(dat[i, ])
   cat(paste("Iteration #:", i, "-", date(), "\n"))
   flush.console()
}

Depending on how you want the printed statements to appear on the
screen, you'd be better off with cat not print, e.g.: 

cat(paste(k,date(),sep=" : "))

If this isn't the solution, post a reply containing information about
your R version, OS, and a reproducible example (simple code & data as I
did) to show us the problem.

HTH

G