This question is a corollary of my attempts to get some experience with creating reproducible reports from R Markdown
documents via knitr
and rmarkdown
R packages. While it seems that .Rmd => HTML
conversion is automated from within RStudio (Knit HTML
button), my attempt to do the same outside of RStudio (Rscript -e 'library(rmarkdown); render("knitr-example-slides-1.Rmd")'
) failed due to, according to the message, lack of pandoc
on my system. This is most likely false, since RStudio somehow managed to perform the conversion. Therefore, it is most likely an access and/or path issue.
Without knowledge of where RStudio maintains pandoc
and details about the access, I have decided to install pandoc
myself. Unfortunately, sudo apt-get install pandoc
has not been very helpful, due to the fact that current version of pandoc
in Ubuntu's trusty
repository (14.04LTS) is 1.12.2.1. According to rmarkdown
's message, version 1.12.3 or higher is required. "Not a big deal", I have thought, and followed instructions on installing pandoc
in case of too old version in repository (http://johnmacfarlane.net/pandoc/installing.html). That requires installing the Haskell platform, which is pretty big and which output is rather verbose. After some time, I finally has been greeted with the following failure message:
[ 6 of 57] Compiling Text.Pandoc.Readers.TeXMath ( src/Text/Pandoc/Readers/TeXMath.hs, dist/build/Text/Pandoc/Readers/TeXMath.o )
src/Text/Pandoc/Readers/TeXMath.hs:30:38:
Ambiguous occurrence `readTeXMath'
It could refer to either `Text.Pandoc.Readers.TeXMath.readTeXMath',
defined at src/Text/Pandoc/Readers/TeXMath.hs:56:1
or `Text.TeXMath.readTeXMath',
imported from `Text.TeXMath' at src/Text/Pandoc/Readers/TeXMath.hs:33:1-19
(and originally defined in `Text.TeXMath.Parser')
Failed to install pandoc-1.12.4.2
cabal: Error: some packages failed to install:
pandoc-1.12.4.2 failed during the building phase. The exception was:
ExitFailure 1
pandoc-citeproc-0.3.1 depends on pandoc-1.12.4.2 which failed to install.
Firstly, I'm not sure how to fix it. Secondly, I very much suspect that there should be an easier way to enjoy generating reproducible reports with rmarkdown
and pandoc
than this. Your advice will be appreciated!
UPDATE (see comments):
Rscript -e 'library(rmarkdown); render("knitr-example-slides-1.Rmd")'
processing file: knitr-example-slides-1.Rmd
|....... | 11%
ordinary text without R code
|.............. | 22%
label: setup (with options)
List of 1
$ include: logi FALSE
Quitting from lines 6-8 (knitr-example-slides-1.Rmd)
Error in eval(expr, envir, enclos) : object 'opts_chunk' not found
Calls: render ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted
Basically, @daroczig answered this question in his comment above, so I will repeat it here, plus will add an answer to the relevant minor question on the issue, appeared after the main question's issue fix.
1) "A binary compiled version of Pandoc is already shipped with RStudio, so you can simply create a symlink, so that you could easily use that outside of the RStudio eco-system: https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md#newer-systems-debianubuntufedora";
2) I have fixed the error, experienced after applying the advice above (see my comment), by calling opts_chunk()
using explicit package reference: knitr::opts_chunk()
, following guidelines here: http://rmarkdown.rstudio.com/authoring_migrating_from_v1.html (thanks to @Yihui for pointing me to this document in a different question: Transitioning research project to knitr-based setup).
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