是否可以直接使用knitr函数knit2pdf()与R Markdown(Rmd)文件?我已经看过各种教程/课堂笔记似乎表明它可以例如here和here(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.
并尝试
library(knitr)
knit2pdf("test.Rmd")
我收到以下错误
结果:
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
单击“编织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
非常感谢。
答案 0 :(得分:7)
您的输入文件格式为rmarkdown
。
您应该使用render()
包中的rmarkdown
函数来编译您的文档。
尝试:
library("rmarkdown")
render("temp.rmd")