【发布时间】:2018-10-16 20:17:00
【问题描述】:
假设我想让我的计算机每分钟计算一次我的年龄,因此我每天运行以下 cron 作业:
*/1 * * * * bash /path/to/birthCalc
birthCalc 本身调用 R 脚本,如下所示:
#!/bin/bash
Rscript birthCalc.R
现在,如果我将 base R 与这样的birthCalc.R 一起使用,这一切都有效:
birthDay <- as.POSIXct ('1919-04-15', format = '%Y-%m-%d')
age <- floor ((as.numeric (Sys.time ()) - as.numeric (birthDay))/(365.25*60*60*24))
但是,如果我尝试通过 lubridate 库使用以下脚本,它就不再起作用了。
library ('lubridate')
birthDay <- as.POSIXct ('1919-04-15', format = '%Y-%m-%d')
age <- floor (lubridate::time_length (Sys.time () - birthDay, "years"))
如果我在 cron 作业中运行 installed.packages (),则会列出 lubridate,因此我假设 cron 作业应该能够找到库。我在其他库中也遇到过这个问题,但选择 lubridate 作为示例。
脚本仅在作为 cron 作业运行时才会失败。我可以从 bash 终端或在 R 中以交互方式运行它。我检查了 cron 是否使用相同的 Rscript 和 R,以及包是否可以访问。我错过了什么?
我正在跑步:
R 版本 3.4.4 (2018-03-15)
平台:x86_64-pc-linux-gnu(64 位)和 Ubuntu 16.04.5 LTS
lubridate_1.7.4
非常感谢, 总时间
【问题讨论】: