5

I'm trying to create a cron command that will use R markdown to create a new html page at specified intervals. I've discovered this is a pandoc issue.

I get the following error message when I log my cron command

Error: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available). Execution halted

Is there a simple bit of code I can add to the .Rmd file to point it to pandoc when executing the cron command?


Preserving the original post. That is below this paragraph.

Everything I want to do is a a file titled test_doc.Rmd.

When I run the following command on the command line, it works successfully:

RScript -e "library(rmarkdown); render(\"/path/test_doc.Rmd\")"

However, when I run that in the crontab, I'm having no success. I'm running a version of this:

25      10      *       *       *       RScript -e "library(rmarkdown); render(\"/path/test_doc.Rmd\")"

I'm baffled. I don't believe it's a filepath issue, since I have other R scripts (not rmarkdown) running in the crontab and working. I am on Mac OS X 10.10.5

Aaron M
  • 125
  • 1
  • 8

3 Answers3

5

The same has happened to me, and I found the answer in a related post regarding your error message (which I haven't even seen):

Error: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available). Execution halted

You have to specify the RSTUDIO_PANDOC environment variable before rendering like so:

Rscript -e 'Sys.setenv(RSTUDIO_PANDOC="/usr/lib/rstudio/bin/pandoc"); rmarkdown::render("test_doc.Rmd")'

This should solve your cronjob issue. It worked for me.

I am assuming that most Linux+RStudio users have pandoc installed in this /usr/... path. Otherwise, query the location using Sys.getenv("RSTUDIO_PANDOC") from an interactive session where the knitting works, and substitute the path in the above command.

Gregor
  • 1,333
  • 9
  • 16
1

Try

25 10 * * *   cd /path && Rscript -e 'rmarkdown::render("test_doc.Rmd")'

which avoids

  1. The full path and gives rmarkdown and knitr a better working directory
  2. The need to 'quote quotes' by having apostrophes on the outside and standard double quotes on the inside.
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
1

Add the path to the beginning of your cron, and redirect the output for debugging purposes:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

*/5 * * * * cd /path/to/script/ && Rscript -e 'library(rmarkdown); rmarkdown::render("your_script.Rmd")' >/path/to/script/cron.log 2>/path/to/script/cronerr.log