0

I have a simple R code that runs once a day to do a specific task. Currently I am using the scheduleR package that has a shiny GUI which allows you to set prefixed time of the day to run the script. However, I would like to have this written in the code rather than depend on the package as the package might or might not be maintained in the future. Example, I want the code to run at 11.50am UTC time everyday. How can i incorporate this into a

while(TRUE){ <code inside> }

loop to get get this done? Any form of simple and elegant way of doing it would be of great help! My main aim is to not depend on any packages to do a scheduled run of my loop.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
user7729135
  • 399
  • 1
  • 3
  • 11
  • @Gregor the point is for me not to depend on these scheduler and some of the systems i run on are headless with no such schedulers – user7729135 Dec 17 '19 at 02:35
  • What systems are you running on that don't have schedulers? Windows, Mac, Linux, Unix, Android... all have schedulers. Cloud platforms? Schedulers. Please edit your question to be more specific then, but I'm surprised you can install R on something that doesn't have a scheduler. – Gregor Thomas Dec 17 '19 at 02:42
  • I've read the question very carefully. You mentioned that you didn't want to use the `scheduleR` R package that comes with a Shiny GUI. The *extremely common* way to do this *extremely common* task is to schedule it in your OS - this is very stable and is not an additional dependency because *you already have an OS*, and every OS has a scheduler built in, waiting for you to use it. I'm trying to show you the good way to do this. – Gregor Thomas Dec 17 '19 at 02:49
  • My clarification request was responding to your comment that I also read, *"some of the systems i run on are headless with no such schedulers"* - I have never heard of such a system, and you don't provide enough information to learn more in your comment, nor mention it in your question. So providing some details on that would be extremely helpful. – Gregor Thomas Dec 17 '19 at 02:51
  • @Gregor would be glad to hear other people's advice and methods. I've had issues with OS schedulers before where computers get shut down etc. It just doesn't make sense to be depending on those when you can host your script in the cloud and not depend on these schedulers and just use the scripts that you write on your own. That's my take on it. – user7729135 Dec 17 '19 at 02:52
  • "In the cloud" is still on a (virtual) OS. If the scheduling is handled in your script, then your script must be running all the time to work, and any problems with (a) the R service or (b) the OS its running on will break it. If the scheduling it done on the OS, then you've eliminated (a), only an OS failure will break it. And you can still use OS-based schedulers on a virtual machine. – Gregor Thomas Dec 17 '19 at 03:00
  • Moreover, if you're on the cloud, the cloud provider has a scheduler so that you don't have to run anything constantly (much cheaper resource wise), [e.g. event bridge in AWS](https://docs.aws.amazon.com/eventbridge/latest/userguide/run-lambda-schedule.html). Now your dependency is a robust cloud service, it's probably 99.999% reliable, and you're not paying for a compute resource 24 hours a day. But again, the answer is to *use a scheduler*. A scheduler is a focused piece of software with one main goal and purpose. R is a statistical programming language. Let each do what they're good at – Gregor Thomas Dec 17 '19 at 03:02
  • 1
    So, overall, I think the dupes I marked answer your question well as asked. [This FAQ](https://stackoverflow.com/q/2793389/903061) has thorough details for Windows, [this answer](https://stackoverflow.com/a/24122775/903061) has suggestions for other OSes, (along with supporting comments like for my points here, *"What a big waste of system resources. Keeping an R instance cycling for the sole purpose of waking up every 60 minutes?"*), and if you're on Azure or AWS or Google Cloud Platform, I would recommend searching for platform-specific solutions---they all have them. – Gregor Thomas Dec 17 '19 at 03:15

0 Answers0