8

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
Aleksandr Blekh
  • 2,462
  • 4
  • 32
  • 64
  • 4
    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 – daroczig Jul 21 '14 at 10:54
  • @daroczig: Awesome, thank you for clear and fast reply! I knew there should be an easier way... :-). Will try and report here. – Aleksandr Blekh Jul 21 '14 at 10:58
  • All right, I followed the instructions for RStudio Server. But, an attempt to process an example `.Rmd` file (https://github.com/yihui/knitr-examples/blob/master/009-slides.Rmd) failed as shown in UPDATE above. Any ideas? (I understand that it's different issue from the original, but it's likely not worth creating a separate question.) – Aleksandr Blekh Jul 21 '14 at 11:06
  • Any solution if I don't want to install RStudio? – January Jun 16 '15 at 11:59
  • 1
    @January: That was quite a while ago, so I'm not sure what `markdown`'s version requirements for `pandoc` are. However, you can definitely try to [install a binary package for your platform](http://pandoc.org/installing.html) and see, if it works. If it doesn't, then I see two alternative options: 1) install `RStudio`; 2) build `pandoc` from the source. Having said that, I'm pretty sure that current binary package of `pandoc` should be enough, unless you need some latest updates. Good luck! – Aleksandr Blekh Jun 16 '15 at 16:39
  • Thanks, turns out that the deb package from pandoc site works perfectly. – January Jun 18 '15 at 08:15
  • @January: My pleasure. Glad it worked out for you. – Aleksandr Blekh Jun 18 '15 at 09:26

1 Answers1

6

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).

Community
  • 1
  • 1
Aleksandr Blekh
  • 2,462
  • 4
  • 32
  • 64
  • 1
    @Yihui: Thank you! I'm just waiting - SO has 2 days waiting period until one can accept her/his own answer :-). I'd appreciate, if you could express your opinion or point me to relevant resources on approaches for using `knitr` and `R Markdown` for complex multi-file/multi-directory projects (main theme of my question: http://stackoverflow.com/questions/24848303/transitioning-research-project-to-knitr-based-setup). – Aleksandr Blekh Jul 22 '14 at 04:48