[R] Schedule R script using cron

Martin Maechler maechler at stat.math.ethz.ch
Thu Apr 12 12:31:09 CEST 2012


>>>>> winie  <winiebook at gmail.com>
>>>>>     on Wed, 11 Apr 2012 18:51:28 -0700 writes:

    > 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 porfile
    > . /home/winie/.profile
    > # script.R will load packages
    > R CMD BATCH /home/script.R 

This has almost nothing to with R, but with running scripts in
cron. On the systems, I've been using, the default shell cron uses is
very simple, e.g.,  PATH = /usr/bin:/bin ,
so I assume that's why you source your (bash ?) profile,
    > . /home/winie/.profile
above.
But that may not be sufficient; there are other settings,
missing in the simple "cron" environment, that your .profile
does not fix up, such as
LD_LIBRARY_PATH, R_LIBS, R_PROFILE, ...
I would add  a line to "your bash script"
  env > /tmp/cron_env_$$
after the  ". /home/winie/.profile" line,
and see how that (cron_env_... file) differs from what you
get when you type 'env' in a regular interactive shell
where (I assume) your  'R CMD BATCH ...' works correctly.

Hoping that helps,
Martin



More information about the R-help mailing list