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
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.
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.
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.
Try
25 10 * * * cd /path && Rscript -e 'rmarkdown::render("test_doc.Rmd")'
which avoids
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With