简体   繁体   English

R脚本的Cron作业失败

[英]Cron job for an R script failing

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 当我自己运行R脚本时,我的R脚本可以按预期工作,但是当我尝试将其作为cron作业运行时,它一直在失败

Error: RStudio not running
Execution halted 

This is the log file for the cron job. 这是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```

This is my cron job set up 这是我的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

``` ```

Sounds like you are trying to do something that can only be run in RStudio. 听起来您正在尝试做只能在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. 在这种情况下,作为建议在这里 ,你可以依赖它无论是运行Rstudio或不是你的脚本的行为。 That can be achieved with the following line : 这可以通过以下行来实现:

isRStudio <- Sys.getenv("RSTUDIO") == "1"

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM