Webscraping R 脚本不来自 crontab 运行

Webscraping R script doesn't run from crontab

我遇到问题 运行使用 R 脚本从 Reddit 抓取帖子作为 cron 作业。当从 R 中手动获取时,该脚本可以完美运行。其他 R 脚本也 运行 从 crontab 中可以正常工作。此外,R 抓取包是专门为不超过 运行 Reddit API.

而构建的

定时任务表:

*/25 * * * * /usr/bin/Rscript "home/ubuntu/cryptoAPI/NLP/NLPupdater.R"

R 脚本:

setwd("/home/ubuntu/cryptoAPI/NLP")
library(RedditExtractoR)#install.packages('RedditExtractoR')
library('httr')
library(data.table)

#1. check for most recent reddit urls
ss.new.Reddit <- fileSnapshot(path="/home/ubuntu/cryptoAPI/NLP/raw", file.info = F)
Reddit.num <- nrow(ss.new.Reddit[[1]])-1

#2. load CCtop100 snapshot from cronjob
Reddit.urls <- rjson::fromJSON(file=paste0('raw/hot.json@limit=50.', Reddit.num))#"raw/hot.json@limit=100.", Reddit.num))

#3. extract urls from list
urlvector <- character(50)    #to 100
for(i in 1:52){               #also to 102
  urlvector[i] <- Reddit.urls$`data`$children[[i]]$data$permalink }

#4. combine w formatting for reddict extractor # add 'http://www.reddit.com'
urlvector.long <- paste0('http://www.reddit.com', urlvector)

#5. run redditextractor
Reddit.comments <- reddit_content(urlvector.long)

#6. save new csv
NLPcsv <- paste0("CSV/reddit-nlp-",Reddit.num,".csv" )
fwrite(Reddit.comments, file=NLPcsv)
fwrite(Reddit.comments, file='current/currentNLP.csv')

cronjob 可以花费多长时间有限制吗?抓取可能需要 3 分钟才能完成。

cronjob 中有错字,忘记了路径中的 /:

*/25 * * * * /usr/bin/Rscript "/home/ubuntu/cryptoAPI/NLP/NLPupdater.R"