使用 cron 调度 R 脚本 [英] Schedule R script using cron
问题描述
我正在尝试使用 cron 安排我的 R 脚本,但它不起作用.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.
以下是我的bash脚本
The following is my bash script
# source my profile
. /home/winie/.profile
# script.R will load packages
R CMD BATCH /home/script.R
推荐答案
考虑这些技巧
使用 Rscript(或更小的)而不是
R CMD BATCH
确保 cron 作业正在运行
Make sure the cron job is running as you
确保脚本自行运行
在详细模式下测试几次
我的盒子正在通过调用 R 脚本的 cronjob 运行一些可见的 CRANberries(我通过 littler 执行,但 Rscript应该也能正常工作).为此,我的 Ubuntu 服务器上 /etc/crontab
中的条目是
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
所以每三小时后的每十六分钟,就会使用我的 ID 运行一个 shell 命令.它切换到工作目录,并调用 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).
看看这个,我实际上可以运行脚本并在其中包含 setwd()
命令....
Looking at this, I could actually just run the script and have setwd()
command in it....
这篇关于使用 cron 调度 R 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!