[R] automation of R? running an R script at a certain time each night?

Tony Plate tplate at acm.org
Fri May 23 18:46:05 CEST 2008


Felipe Carrillo wrote:
> Hi:
> Edward, were you able to automate the process? if so,
> do you mind giving me a hint on how you did it? I am
> facing the same problem. I created a batch file which
> it runs fine using the task scheduler but only opens
> Tinn-R and R but it doesn't execute my script.
> My task scheduler executes everyday at 8:00 am
> This is my batch file:
> @echo off
> Start "" "C:\Program Files\R\R-2.7.0\bin\Rgui.exe"
>  start "" "C:\Documents and
> settings\Desktop\Software\MyScript.r"
> 
> What am I missing?

Looks to me that the batch file above starts up the R GUI, 
and opens an editor, so it sounds like it is doing exactly 
what you're asking it to.

Here's how I can get R to run as a scheduled task in Windows XP:

Create a new "Scheduled Task" with the following in the 
"Run:" box:
C:\Rbuild\R-2.6.2\bin\Rcmd.exe BATCH c:/Temp/Rtest.R

Then schedule it how I want it to run.  Here's the contents 
of my .R file and the output:

$ cat c:/Temp/Rtest.R
cat(file="c:/Temp/Rtest.txt", date(), "\n", append=TRUE)

$ cat c:/Temp/Rtest.txt
Fri May 23 10:34:22 2008
Fri May 23 10:34:50 2008
Fri May 23 10:40:01 2008

(I'm sure there are dozens of other ways of doing this, but 
the above worked for me.)

-- Tony Plate

> 
> 
> --- Edward Wijaya <ewijaya at gmail.com> wrote:
> 
>> You might try cron job under Windows.
>>
>> http://drupal.org/node/31506
>>
>> HTH.
>>
>> - Edward
>>
>> On Thu, May 22, 2008 at 8:51 AM, Thomas Pujol
>> <thomas.pujol at yahoo.com> wrote:
>>> I am using R in a Windows environment.
>>>
>>> I store my data in a Microsoft SQL database that
>> gets updated automatically nightly.  Once my SQL db
>> is updated, I wish to automatically run an R
>> "script"
>>> Any tips on "good" ways to approach this task?
>>>
>>> Is there an easy way to "launch" an R script using
>> the Windows or other "scheduler"? Can I have an
>> R-script run every hour, and within the script check
>> to determine if my database is updated, and proceed
>> only if it is updated?
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained,
>> reproducible code.
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained,
>> reproducible code.
>>
> 
> 
>  Felipe D. Carrillo
>   Fishery Biologist
>   Department of the Interior
>   US Fish & Wildlife Service
>   California, USA
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list