1

In my code I plot a function and then raise a dialog to ask the user about it. The issue is that the dialog is raised before the plot is updated, so the user sees whatever was last in the plot window (I'm using R-studio). How can I solve this?

Example:

for(i in (1:3)) {
   x = (1:100); #not the real vectors...just an example
   f = (601:700);
   plot(x,f)
   ans = winDialog(type = c("yesno"), "is it any good?")
}
Jaap
  • 81,064
  • 34
  • 182
  • 193
Geva Tal
  • 340
  • 3
  • 14

1 Answers1

0

Searching for "R flush plot" led me to this solution. At least on my system I had to replace Sys.sleep(0) by Sys.sleep(1). But then it works.

for(i in (1:3)) {
  x = (1:100); #not the real vectors...just an example
  f = x^i
  plot(x,f)
  Sys.sleep(1)
  ans = winDialog(type = c("yesno"), "is it any good?")
}
Community
  • 1
  • 1
mra68
  • 2,960
  • 1
  • 10
  • 17
  • Weird, I've tried that before posting with Sys.sleep(0.25) but it didn't work. Seems like 1 sec does the trick for me as well, wonder if that's bulletproof or at different conditions one second wouldn't cut it as well. Thanks! – Geva Tal Dec 28 '15 at 12:03