Do you want to be doing other things with the R terminal in the meantime?

Are you OK with the terminal being locked up between runs and just want to see 
the output updated?
Is it OK to have a new instance of R run the function?


If the last one is doable then you can have your OS scheduled to run a script 
every 5 minutes and the script runs your function.  How to do this depends on 
your OS, fairly easy with chron on linux and related OS's (you can see the 
updated file using the tail program, some versions will wait for new info to be 
appended and show it automatically).  I have done this in windows before, but 
it takes several clicks and I need to rediscover the correct sequence each time.

If you are happy with the 2nd set of conditions then you can just use a while 
loop to repeatedly run the function and include a call to Sys.sleep to wait the 
required time.  Note that if your function takes more than a couple of seconds 
then you will want to reduce the amount of time accordingly.  If the amount of 
time your function takes varies then you will not be running exactly every 5 
minutes.

If you need the 1st set of conditions, then you could load the tcltk2 package 
and use the tclTaskSchedule function.  This is the most dangerous situation, 
you could end up with messed up data if you are trying to edit something at the 
same time the function runs and also tries to use/edit it.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of RobertJK
> Sent: Friday, August 12, 2011 12:03 PM
> To: r-help@r-project.org
> Subject: [R] Automating an R function call
> 
> Any way to run an R function every 5 minutes from the R terminal?
> Searched
> around but couldn't find any answers. Thanks!!
> Robert
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Automating-
> an-R-function-call-tp3740070p3740070.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to