[R] running functions at fixed times
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Tue Jan 9 08:45:23 CET 2001
On Tue, 9 Jan 2001 detlef.steuer at unibw-hamburg.de wrote:
> Hi!
>
> I can only speak for the Linux/Unix enviroment:
>
> Try
>
> while(TRUE)
> {
> system("sleep 60")
>
> mydata <- read.table(...)
> }
>
> to update mydata after a 60 second break.
> An alternative is to use "cron" or "at". Both allow the specification
> of exact execution times, while the "while" approach tries to imitate
> a real time system.
>
There is a Sys.sleep function in R these days. BUT, under that
approach, the R process does nothing but update its internal copy of
.RData, and I don't think that is useful. In particular, nothing can ever
be done with mydata, as nothing else can be run.
What I think Jeff Miller wants is for a task to be run in the background of
the R session to update mydata, while he gets on with some work at the
prompt. That's a lot harder. R is single-threaded and does not have
(user-specified timer) events. Not quite impossible, though, as it does
have an event loop to handle UI events, and one could subvert this by some
C programming.
The difference between Sys.sleep(60.0) and system("sleep 60") is that the
former keeps the event loop ticking over, and that it works across
platforms.
Jeff mentioned S. S version 4 does have events and monitors, but I have
never been sure how much of that is operational in S-PLUS 5/6.x.
> Have a nice day
> Detlef
>
>
> Detlef Steuer ** Universität der Bw ** 22043 Hamburg
> Tel: (0049) (0)40/6541-2819
> steuer at unibw-hamburg.de
>
>
>
> On 09-Jan-01 Jeff Miller wrote:
> >
> > Is there an easy way to automatically run an R function at fixed
> > intervals of time?
> >
> > For example, if I have a file, mydata.txt, which is updated every
> > minute or so,
> > is there an R or an S function which would execute the command
> >
> > mydata <- read.table("mydata.txt")
> >
> > each minute? Basically I just want "mydata" to be constantly updated
> > without
> > my having to bother with it.
> >
> > Thanks in advance,
> >
> > Jeff Miller
> >
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> > -
> > 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
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> > _
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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