当我自己运行它时,我的R脚本按预期工作,但当我尝试将其作为一个cron作业运行时,它仍然无法说
Error: RStudio not running
Execution halted
这是cron作业的日志文件。
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工作设置
## 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
```
答案 0 :(得分:2)
听起来你正在尝试做一些只能在RStudio中运行的东西。也许你们其中一个函数试图调用一个只能在RStudio中运行的函数,例如here中的一个函数?
在这种情况下,根据建议here,您可以使脚本的行为取决于它是否在Rstudio中运行。这可以通过following line:
来实现isRStudio <- Sys.getenv("RSTUDIO") == "1"
希望这有帮助。