Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule R script using cron

Tags:

r

cron

I am trying to schedule my R script using cron, but it is not working. It seems R can not find packages in cron. Anyone can help me? Thanks.

The following is my bash script

# source  my profile
. /home/winie/.profile
# script.R will load packages
R CMD BATCH /home/script.R 

like image 540
user1589 Avatar asked Apr 12 '12 01:04

user1589


People also ask

What does 30 * * * * mean in crontab?

*/30 * * * * your_command. this means "run when the minute of each hour is evenly divisible by 30" (would run at: 1:30, 2:00, 2:30, 3:00, etc) example #3. 0,30 * * * * your_command. this means "run when the minute of each hour is 0 or 30" (would run at: 1:30, 2:00, 2:30, 3:00, etc)


1 Answers

Consider these tips

  1. Use Rscript (or littler) rather than R CMD BATCH

  2. Make sure the cron job is running as you

  3. Make sure the script runs by itself

  4. Test it a few times in verbose mode

My box is running the somewhat visible CRANberries via a cronjob calling an R script (which I execute via littler but Rscript should work just as well). For this, the entry in /etc/crontab on my Ubuntu server is

# every few hours, run cranberries
16 */3 * * *    edd     cd /home/edd/cranberries && ./cranberries.r

so every sixteen minutes past every third hour, a shell command is being run with my id. It changes into the working directory, and call the R script (which has executable modes etc).

Looking at this, I could actually just run the script and have setwd() command in it....

like image 103
Dirk Eddelbuettel Avatar answered Oct 28 '22 06:10

Dirk Eddelbuettel