Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandoc while using R markdown with a cron command

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

like image 918
Aaron M Avatar asked Dec 21 '16 18:12

Aaron M


People also ask

Does Rmarkdown use Pandoc?

A recent version of Pandoc (>= 1.12. 3) is required to use the rmarkdown package. RStudio also automatically includes this so you do not need to download Pandoc if you plan to use rmarkdown from the RStudio IDE.

Does RStudio include Pandoc?

Note. Usually you do not need to install Pandoc if you use the RStudio IDE, because the IDE has bundled a version of Pandoc. If you have installed a version of Pandoc by yourself and want to use this version instead, you may use the dir argument of this function.


2 Answers

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.

like image 195
Gregor Avatar answered Sep 22 '22 02:09

Gregor


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.
like image 27
Dirk Eddelbuettel Avatar answered Sep 19 '22 02:09

Dirk Eddelbuettel