在Ubuntu 14.04LTS上安装Pandoc出现问题,用于与R Markdown一起使用。

8
这个问题是我尝试通过knitr和rmarkdown R包从R Markdown文档创建可重现报告的次要问题。虽然似乎在RStudio中可以自动进行.Rmd => HTML转换(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平台,它非常庞大且输出相当冗长。经过一段时间,我最终收到了以下失败消息:
[ 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生成可重复报告的方法应该有更简单的方式期待您的建议!

更新(参见评论):

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

4
RStudio已经附带了Pandoc的二进制编译版本,因此您可以创建符号链接,以便在RStudio生态系统之外轻松使用:https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md#newer-systems-debianubuntufedora - daroczig
有没有其他解决方案,如果我不想安装RStudio? - January
1
@January:那是相当久以前的事了,所以我不确定 markdownpandoc 的版本要求是什么。但是,你可以尝试为你的平台安装二进制包,看看是否可行。如果不行,那么我看有两个备选方案:1)安装 RStudio;2)从源代码构建 pandoc。话虽如此,我相信当前的 pandoc 二进制包应该足够使用,除非你需要一些最新的更新。祝你好运! - Aleksandr Blekh
谢谢,结果发现 pandoc 网站上的 deb 包完美运行。 - January
@January:很高兴能帮到你,我很愉快地听到问题得到解决。 - Aleksandr Blekh
显示剩余2条评论
1个回答

6
基本上,@daroczig在评论中已经回答了这个问题,所以我在这里重复一下,并增加一个与主要问题修复后出现的相关小问题的答案。
1) "Pandoc的二进制编译版本已经随RStudio一起提供,因此您可以创建一个符号链接,以便您可以轻松地在RStudio生态系统之外使用它:https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md#newer-systems-debianubuntufedora";
2) 我通过使用显式包引用来调用knitr::opts_chunk()解决了上述建议后遇到的错误(请参见我的评论),按照这里的指导方针: http://rmarkdown.rstudio.com/authoring_migrating_from_v1.html(感谢@Yihui在另一个问题中指向我这个文件:Transitioning research project to knitr-based setup)。

1
@Yihui:谢谢!我只是在等待 - SO有2天的等待期,直到一个人可以接受自己的答案 :-)。如果您能表达您的意见或指向相关资源,以便使用knitrR Markdown处理复杂的多文件/多目录项目(我的问题的主题:http://stackoverflow.com/questions/24848303/transitioning-research-project-to-knitr-based-setup),我将不胜感激。 - Aleksandr Blekh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接