R脚本的Cron作业失败 [英] Cron job for an R script failing
问题描述
我的R脚本在单独运行时可以按预期工作,但是当我尝试将其作为cron作业运行时,它总是会失败
My R script works as intended when I run it on its own, but when I try to run it as a cron job, it keeps failing saying
Error: RStudio not running
Execution halted
cron作业的日志文件。
This is the log file for the cron job.
Loading required package: methods
Attaching package: ‘lubridate’
The following object is masked from ‘package:base’:
date
Linkging to ImageMagick 6.8.9.9
Enabled features: cairo, fontconfig, freetype, fftw, lcms, pango, rsvg, x11
Disabled features: ghostscript, webp
Loading required package: bitops
Attaching package: ‘gmailr’
The following object is masked from ‘package:lubridate’:
date
The following object is masked from ‘package:utils’:
history
The following objects are masked from ‘package:base’:
body, date, labels, message
Error: RStudio not running
Execution halted```
这是我的cron工作设置
This is my cron job set up
## cronR job
## id: job_3284804a12afb8b01664417646b9fc7f
## tags:
## desc: I execute things
0-59 * * * * /usr/lib/R/bin/Rscript '/home/rstudio/dev/082017_email/weekly_email.R' >> '/home/rstudio/dev/082017_email/weekly_email.log' 2>&1
'' `
推荐答案
听起来像您正在尝试做只能在RStudio中运行的操作。也许您中的一个功能试图调用只能在RStudio中运行的功能,例如此处?
Sounds like you are trying to do something that can only be run in RStudio. Maybe one of you functions is trying to call a fucntion that can only be run in RStudio, for example one of the functions from here?
在这种情况下,如建议在这里,您可以根据脚本是否在Rstudio中运行来确定其行为。可以通过下一行:
In that case, as suggested here, you can make the behavior of your script dependent on whether it's run in Rstudio or not. That can be achieved with the following line:
isRStudio <- Sys.getenv("RSTUDIO") == "1"
希望这会有所帮助。
这篇关于R脚本的Cron作业失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!