Knitr2pdf 不工作 for.Rmd 文件,使用 rmarkdown::render()

Knitr2pdf does not work for.Rmd file, use rmarkdown::render()

在之前的一个问题中,我尝试设置eclipse与knitr2pdf一起工作,Yihui Xie非常友好地给了我一个非常及时的回答。现在我更进了一步。

这是我的文件

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

我试图找到报告类似问题的问题,答案是尝试使用 render 而不是 knit2pdf,这不是我想要的。这不是 eclipse 的问题,但我未能正确 运行 knit2pdf。手动 运行 命令 knit2pdf("test_knit2pdf.Rmd") 得到同样的错误。再一次,也许有人 运行 遇到了类似的问题并且能够帮助我,我的文件格式是否错误,我是否遗漏了什么?

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

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

的 pandoc

转到 eclipse,运行 > 外部工具 > 外部工具配置 点击wikitext + R文档处理 在下拉菜单中,右上角,名为load Preset example,单击PDF using Rmarkdown,单步。在 2/ produce output 中,所有内容都配置为生成 pdf 作为输出。

我关注了这个优秀的posthttps://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