Can't print to console from within while-loop in R

Viewed 1085

I am running this piece of code from a Rgui.exe window in Windows:

i = 1
while(i <= 10){
    cat(i, "\n") 
    i = i + 1
    Sys.sleep(2)
}

The cat() piece does not get output every 2 seconds, but only collectively at the end of the 20 seconds, i.e. 10 iterations.

I am used to print() and cat() calls getting output immediately, so I don't know why this is happening here.

How do I make R print immediately in each iteration?

1 Answers
Related