I have an R script that generates a report based on the current contents of a database. This database is constantly in flux with records being added/deleted many times each day. How can I ask my computer to run this every night at 4 am so that I have an up to date report waiting for me in the morning? Or perhaps I want it to re-run once a certain number of new records have been added to the database. How might I go about automating this? I should mention I'm on Windows, but I could easily put this script on my Linux machine if that would simplify the process.
2 Answers
For windows, use the task scheduler to set the task to run for example daily at 4:00 AM
It gives you many other options regarding frequency etc. http://en.wikipedia.org/wiki/Windows_Task_Scheduler
How can I ask my computer to run this every night at 4 am so that I have an up to date report waiting for me in the morning?
You can set up a cronjob on a Linux system. These are run at the set time, if the computer is on. To do so, open a terminal and type:
crontab -e
And add:
00 4 * * * r source(/home/FilePath/.../myRscript.R)
Source: Stack Overflow
-
$\begingroup$ Excellent! Anything similar on Windows? I suppose if I want to condition it on something like the size of the database I can have my R script check that at the beginning and either stop or continue generating the report. What if I add this to the beginning of the R script and then I want to run it every 15 minutes? Do I need 24x4
crontab
commands? Or can I iterate it somehow? $\endgroup$– rnorbergCommented May 14, 2014 at 14:58 -
1$\begingroup$ @rnorberg You can set a cron job to repeat in any periodic time pattern as long as the time period is constant, and greater than 1 minute. Read the man page for more details, or such google "crontab". Lots of stuff available. $\endgroup$– asheeshrCommented May 14, 2014 at 15:14