Reputation: 11441
On a server, I want cron to run an R script which renders an HTML page using rmarkdown. RStudio server is installed. The crontab entry for user mark
is:
* * * * * Rscript R/test.R >> /tmp/cron.log 2>&1
test.R:
library(rmarkdown)
getwd()
render("R/test.Rmd")
The cron.log
file shows
[1] "/home/mark"
Error: pandoc version 1.12.3 or higher is required and was not found.
Execution stopped
Running test.R
from the console, however, works fine:
Rscript R/test.R
The RStudio server version of pandoc
was added to usr/local/bin
using a symlink as described here). Checking the pandoc version in the console gives
mark@myserver:$ pandoc -v
pandoc 1.15.2
which is not the old version as in the log file. Also, the binary appears to be found
mark@myserver:$ which pandoc
/usr/local/bin/pandoc
I am not sure what is going on. Any ideas?
Upvotes: 2
Views: 1655
Reputation: 8812
It's likely that /usr/local/bin
is being added to your $PATH
in your bash shell, but that your cron job is not running under bash and so doesn't have pandoc on the path. To test this assumption, add these lines to your R file:
Sys.getenv("PATH")
Sys.which("pandoc")
If that's indeed the case, you could have your R script append to $PATH
as appropriate, or have cron run the job under a bash shell.
If all else fails, you could set RSTUDIO_PANDOC
:
Sys.setenv(RSTUDIO_PANDOC = "/usr/local/bin/pandoc")
Upvotes: 5