pet*_*r_w 8 r knitr r-markdown
是否可以直接使用knitr函数knit2pdf()与R Markdown(Rmd)文件?我已经看过各种教程/课堂笔记似乎表明它可以在这里和这里(Ctrl + F"knit2pdf"中的任何一个).
但是当我拿一个简单的rmd文件(保存为"test.rmd")时
---
title: "knit2pdf test"
author: "A Aaronson"
date: "Thursday, February 19, 2015"
output: pdf_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Run Code Online (Sandbox Code Playgroud)
并尝试
library(knitr)
knit2pdf("test.Rmd")
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
结果是:
output file: test.md
Error: running 'texi2dvi' on 'test.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~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "test.md" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1
Run Code Online (Sandbox Code Playgroud)
单击"编织PDF"按钮始终会成功生成pdf.我错过了一个中间步骤吗?
我应该补充说,带有Rnw文件的knit2pdf()正如我所期望的那样工作,尽管我仍然收到警告
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "rnwtest.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1
Run Code Online (Sandbox Code Playgroud)
非常感谢.
您的输入文件rmarkdown格式正确.
您应该使用包中的render()函数rmarkdown来编译文档.
尝试:
library("rmarkdown")
render("temp.rmd")
Run Code Online (Sandbox Code Playgroud)
