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

Chris Marshall chrism at norcomnetworks.com
Mon Aug 20 20:15:26 CEST 2001


 Perfect!  Works like a charm!

Thank you so much.  I can't believe I got an answer in an hour.

R has to be one of the best supported tools in existance.

Chris Marshall

-----Original Message-----
From: Thomas Lumley
To: Chris Marshall
Cc: 'r-help at lists.R-project.org'
Sent: 8/20/01 2:06 PM
Subject: Re: [R] using R to generate resizable real-time plots

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