Re: [R] Automating an R function call
Thanks for your help everyone! I'm happy enough with an asynchronous solution here. Thanks! Robert -- View this message in context: http://r.789695.n4.nabble.com/Automating-an-R-function-call-tp3740070p3740333.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ 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] 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.
Re: [R] Automating an R function call
Hey, Sys.sleep(300) ?Sys.sleep Ken Hutchison On Aug 12, 2554 BE, at 2:03 PM, RobertJK rkind...@gmail.com wrote: 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.
Re: [R] Automating an R function call
On 12/08/2011 2:03 PM, RobertJK wrote: Any way to run an R function every 5 minutes from the R terminal? Searched around but couldn't find any answers. Thanks!! Yes, but not in the background: repeat { f() Sys.sleep(300) } If you want it run in the background, get your OS to run R to do it. (It's possible the tcltk package will give you access to some tcl way to set a background process; I don't know. Similarly, you could call out to C and start up another thread, etc., but R itself is single-threaded.) Duncan Murdoch __ 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.
Re: [R] Automating an R function call
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.
Re: [R] Automating an R function call
On Aug 12, 2011, at 21:26 , Duncan Murdoch wrote: On 12/08/2011 2:03 PM, RobertJK wrote: Any way to run an R function every 5 minutes from the R terminal? Searched around but couldn't find any answers. Thanks!! Yes, but not in the background: repeat { f() Sys.sleep(300) } If you want it run in the background, get your OS to run R to do it. (It's possible the tcltk package will give you access to some tcl way to set a background process; I don't know. Similarly, you could call out to C and start up another thread, etc., but R itself is single-threaded.) For asynchronuos within-R possibilities check out tkafter in the tcltk package. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com Døden skal tape! --- Nordahl Grieg __ 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.
Re: [R] Automating an R function call
Hey, Also, if your function varies in time (less than 5 minutes) then you could use total.time.difference=system.time(some.function)[1)] # (for user time) and you could plug this into your Sys.sleep() (which accepts decimal seconds) if you can #accept an error on the order of hundredths of seconds (and don't need to run another process in said console) Ken On Fri, Aug 12, 2011 at 3:41 PM, peter dalgaard pda...@gmail.com wrote: On Aug 12, 2011, at 21:26 , Duncan Murdoch wrote: On 12/08/2011 2:03 PM, RobertJK wrote: Any way to run an R function every 5 minutes from the R terminal? Searched around but couldn't find any answers. Thanks!! Yes, but not in the background: repeat { f() Sys.sleep(300) } If you want it run in the background, get your OS to run R to do it. (It's possible the tcltk package will give you access to some tcl way to set a background process; I don't know. Similarly, you could call out to C and start up another thread, etc., but R itself is single-threaded.) For asynchronuos within-R possibilities check out tkafter in the tcltk package. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com Døden skal tape! --- Nordahl Grieg __ 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. [[alternative HTML version deleted]] __ 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.