[R] using R to generate resizable real-time plots

Thomas Lumley tlumley at u.washington.edu
Mon Aug 20 20:06:45 CEST 2001


On Mon, 20 Aug 2001, Chris Marshall wrote:

> I am trying to use R to repeatedly plot data to an X11 device from a file
> that is being updated every five minutes.  My initial strategy was to use a
> loop in R that roughly looks like this
>
> while (TRUE){
>    system("sleep 10")
>    plot(x,y)
> }
>
> However, this had an interesting side effect: when I try to resize the plot
> window under X, R never processes the resize events like it would if I had
> invoked R interactively and typed a command into the xterm I was running R
> from.
>
> I would like to get around this somehow so that R does not go to sleep like
> this and stop processing X events.
>
 Well, you did *ask* it to go to sleep ;-)

The Sys.sleep() function is designed for this. It waits without suspending
the event loop so the following should work

repeat({
   Sys.sleep(10)
   plot(x,y)
   })

(or use while(TRUE){} instead of repeat() if you prefer)

However, there appears to be a bug. On my machine (Debian Linux) does
works, but if you interrupt Sys.sleep() with CTRL-C and then rerun it
there is a segfault.

If you don't plan to interrupt the loop with CTRL-C you should be fine
(and you may be fine on other OSes).


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list