scheduling r functions after every particular time interval

前端 未结 1 1405
半阙折子戏
半阙折子戏 2021-01-13 16:08

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 d

相关标签:
1条回答
  • 2021-01-13 16:35

    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)
    }
    
    0 讨论(0)
提交回复
热议问题