4

Possible Duplicate:
Plotting during a loop in RStudio

I'm trying to monitor the status of a convergence loop, and I can't seem to get it to update the graph each time it iterates.

Here's some sample code:

print(plot(c(0,1)~c(0,100)))
for(i in seq(100)) {
  Sys.sleep(.1)
  print(points( runif(1)~i ))
}

Note that the graph only updates after everything's been plotted. I need it to update each loop iteration. I thought print would do that, but it's not working.

Update

This is an RStudio-specific problem, as it works properly in base R. Is there a way to force graphing in RStudio each loop iteration?

Community
  • 1
  • 1
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235

1 Answers1

7

Start up a separate graphics device with X11() (or win() on windows?) and use that.

Although plots seem to update okay on my RStudio setup. My test is simply:

plot(1:10);for(i in 1:10){points(10-i,i);Sys.sleep(1)}

I see the first set of 10 points, then the next set appear at one second intervals, in the RStudio embedded graphics window.

Spacedman
  • 92,590
  • 12
  • 140
  • 224