关于knitr:在Ubuntu 14.04LTS上进行Pandoc安装时遇到问题,无法与R Markdown一起使用

Trouble with Pandoc installation on Ubuntu 14.04LTS for using with R Markdown

这个问题是我尝试通过knitrrmarkdown R软件包从R Markdown文档创建可再现报告的一些经验的必然结果。虽然消息似乎是从RStudio(Knit HTML按钮)中自动进行的,但我尝试在RStudio(Rscript -e 'library(rmarkdown); render("knitr-example-slides-1.Rmd")')之外进行相同的操作却失败了,原因是,根据消息,我的计算机上缺少pandoc系统。这很可能是错误的,因为RStudio以某种方式设法执行了转换。因此,很可能是访问和/或路径问题。

在不了解RStudio在哪里维护pandoc的知识以及访问权限的详细信息的情况下,我决定自己安装pandoc。不幸的是,由于在Ubuntu trusty存储库(14.04LTS)中pandoc的当前版本是1.12.2.1,因此sudo apt-get install pandoc并不是很有帮助。根据rmarkdown的消息,需要1.12.3或更高版本。我认为,"没什么大不了的",并遵循了有关在存储库中版本太旧的情况下安装pandoc的说明(http://johnmacfarlane.net/pandoc/installing.html)。这就需要安装Haskell平台,该平台很大,输出相当冗长。一段时间后,我终于收到以下失败消息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[ 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.

首先,我不确定如何修复它。其次,我非常怀疑应该有比这更简单的方法来享受使用rmarkdownpandoc生成可重复报告的乐趣。您的建议将不胜感激!

更新(请参阅评论):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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


基本上,@ daroczig在上面的评论中回答了这个问题,因此我将在此处重复,再加上将在主要问题的问题修复之后出现的有关该问题的次要问题的答案。

1)" RStudio已随附Pandoc的二进制编译版本,因此您只需创建一个符号链接,即可在RStudio生态系统之外轻松使用该符号链接:https://github.com/rstudio /rmarkdown/blob/master/PANDOC.md#newer-systems-debianubuntufedora";

2)我已解决上述错误,在应用上述建议后(请参阅我的评论),通过使用明确的包引用:knitr::opts_chunk(),并遵循以下指南,调用了opts_chunk(): /authoring_migrating_from_v1.html(感谢@Yihui在另一个问题中向我指出了本文档:将研究项目过渡到基于编织的设置)。