Knitr2pdf不适用于.rmd文件,使用rmarkdown :: render()

时间:2017-10-27 20:02:38

标签: r eclipse knitr statet

在之前的一个问题knitr2pdf eclipse : how to configure?中,我试图设置eclipse与knitr2pdf一起工作,谢逸辉非常友好地给了我一个非常及时的答案。现在我更进了一步。

这是我的档案

---
title: "knit2pdf test"
author: "cedric"
date: "27/10/2017"
output: pdf_document
---


```{r}
plot(rnorm(1:10))
```

运行此文件时,我得到以下答案

knit2pdf(input= "C:/workspace/p/example_scripts/test_knit2pdf.Rmd")


processing file: C:/workspace/p/example_scripts/test_knit2pdf.Rmd
  |................................                                 |  50%
  ordinary text without R code

  |.................................................................| 100%
label: unnamed-chunk-1

output file: test_knit2pdf.md

Error: running 'texi2dvi' on 'test_knit2pdf.md' failed

LaTeX errors:
! Emergency stop
*** (job aborted, no legal \end found)

!  ==> Fatal error occurred, no output PDF file produced!
!  ==> Fatal error occurred, no output PDF file produced!
In addition: Warning message:
running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\texify.exe" --quiet --pdf "test_knit2pdf.md" --max-iterations=20 -I "C:/Program Files/R/R-3.4.2/share/texmf/tex/latex" -I "C:/Program Files/R/R-3.4.2/share/texmf/bibtex/bst"' had status 1 

我试图找到报告类似问题的问题,Using knit2pdf with Rmd files答案是尝试使用render而不是knit2pdf,这不是我想要的。这不是eclipse的问题,但我没能正确运行knit2pdf。手动运行命令knit2pdf(" test_knit2pdf.Rmd")会得到相同的错误。再说一次,也许有人会遇到类似的问题并能够帮助我,我的文件是否形成错误,我错过了什么?

1 个答案:

答案 0 :(得分:1)

要使用rmarkdown :: render()处理Rmd文档,必须执行以下步骤

安装pandoc 编辑Windows路径,系统环境变量,复制到pandoc的路径,该路径位于 C:\ Users \ me \ AppData \ Local \ Pandoc

去eclipse,Run>外部工具>外部工具配置 单击wikitext + R文档处理 在下拉菜单中,topright,命名为load Preset示例,使用Rmarkdown单击PDF,单步执行。在2 /产出输出中,所有内容都配置为生成pdf作为输出。

enter image description here

我遵循了这篇优秀的帖子https://www.r-bloggers.com/processing-rmarkdown-documents-with-eclipse-and-statet/,这对我帮助很大。

现在我可以通过点击eclipse中的render_markdown按钮来运行

rmarkdown::render(input= "C:\\workspace\\p\\example_scripts\\testmd.Rmd", output_format= "pdf_document", output_file= "C:\\workspace\\p\\example_scripts\\testmd.pdf", encoding= "UTF-8")


processing file: testmd.Rmd
  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-1
  |.................................................................| 100%
  ordinary text without R code


output file: testmd.knit.md

"C:/Users/me/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS testmd.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc2806c2b6c59.pdf --template "C:\PROGRA~1\R\R-34~1.2\library\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" 

Output created: C:\workspace\p\example_scripts\testmd.pdf