# Running an R script programmatically [closed]

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.

• This is off-topic and has probably already been answered a hundred times on more general computing forums. Flagged. – Spacedman Jun 14 '14 at 9:31

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


00 4 * * * r source(/home/FilePath/.../myRscript.R)

• 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? – rnorberg May 14 '14 at 14:58