Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scheduling r functions after every particular time interval

Tags:

r

I have one r function i want to run it automatically(scheduling) after every predefined time interval (example after every 5 mins) Is it possible if yes then how it can be done.

like image 791
jan5 Avatar asked Dec 10 '22 01:12

jan5


1 Answers

Ideally you should use the system scheduler for this: cron on a Unix system or Scheduled Tasks on a Windows system.

There may be some requirement that means you can't spawn a new process for each invocation of the function. If so then use an infinite loop with a call to Sys.sleep() to wait until the next invocation is due.

repeat {
    startTime <- Sys.time()
    runFunction()
    sleepTime <- startTime + 5*60 - Sys.time()
    if (sleepTime > 0)
        Sys.sleep(sleepTime)
}
like image 87
David Heffernan Avatar answered Jan 31 '23 10:01

David Heffernan