Skip to content

How to Run R Programs in a Scheduled Way

3 messages · Thorsten Muehge, Uwe Ligges, Tony

#
Thorsten Muehge wrote:
Write some Windows command script (also referred to as batch file) that 
calls Rterm with some input file or R CMD BATCH. Then tell your 
scheduler to run that file as you like.

For me this worked very well with Windows XP and Windows Server 2003. In 
Windows Server 2008 64-bit (and hence I guess the same in Vista) I found 
that the new scheduler runs R extremely slow (by a factor of roughly 10 
if some relevant amount of CPU performance and IO traffic is requested) 
so that I decided to moved to a cron implementation. At least, I have 
not found any solution for the Windows 2008 task scheduler so far.

Uwe Ligges
#
Hi Thorsten, the way i do this (on Windows Vista Ultimate, SP1) is to
create a batch file and then have windows task scheduler call it at a
specific time. For example, to create my batch file i open up Notepad
and type the following single line into it:


"C:\Program Files\R\R-2.8.1\bin\R.exe" CMD BATCH --vanilla --slave "\
\PFO-SBS001\Redirected\tonyb\Desktop\myScript.R"


so this is basically: "[location of R.exe]" CMD BATCH --vanilla --
slave  "[location of your R script file]"

I then save this Notepad text file, and change the extension from
'.txt' to '.bat'. If you double click on this .bat file, it will run
your script.

All you have to do now is have scheduler point to your new .bat
file  :-)

HTH,
Tony Breyal

P.S. Be careful with windows scheduler (at least in Vista) if you want
the same script to run several times a day (e.g. setting a daily
trigger starting at 0900 and repeating every 2 hours for a duration of
12 hours). Instead of stopping when expected, it will just keep going
every 2 hours regardless of the duration you set (the only way around
this that i found was to programme in time constraints into my r
script itself, such as only running the script if a condition like
9<=current.hour & current.hour<=21 are met.)
On 22 Jan, 09:10, Thorsten Muehge <MUE... at de.ibm.com> wrote: