Pandoc while using R markdown with a cron command
Asked Answered
A

3

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

Apostate answered 21/12, 2016 at 18:41 Comment(1)
Was wondering if you ever managed to solve thisLatter
R
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.

Radman answered 21/11, 2020 at 23:23 Comment(0)
C
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.
Crabb answered 21/12, 2016 at 18:45 Comment(3)
I am still not getting this to work in the crontab (it does in terminal). Might it be a permissions issue? Or issue with the packages?Apostate
Do you use /etc/crontab or a per user crontab? I always start by just touch /tmp/BeenHereNowDeleteMe.txt or some such and build up from there.Crabb
I've been on a per user crontab.Apostate
T
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
Tchad answered 28/3, 2017 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.