本文介绍了在Rmd文件中使用knit2pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Rnitdown(Rmd)文件直接使用knitr函数knit2pdf()?我看过各种教程/课堂笔记,似乎暗示它可以例如此处和(或Ctrl + F"knit2pdf").

Is it possible to use the knitr function knit2pdf() directly with R Markdown (Rmd) files? I've seen various tutorials/class notes that seem to suggest it can e.g. here and here (Ctrl+F "knit2pdf" in either).

但是当我使用一个简单的rmd文件(保存为"test.rmd")时

But when I take a simple rmd file (saved as "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.那我错过了中间步骤了吗?

Clicking the "Knit PDF" button always successfully generates a pdf. So am I missing an intermediate step?

我应该添加带有Rnw文件的knit2pdf()可以正常工作,尽管我仍然会收到警告

I should add that knit2pdf() with Rnw files is working as expected for me, though I do still get the warning

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 

非常感谢您的帮助.

推荐答案

您的输入文件为rmarkdown格式.

您应该使用rmarkdown包中的render()函数来编译文档.

You should use the render() function in the rmarkdown package to compile your document.

尝试:

library("rmarkdown")
render("temp.rmd")

这篇关于在Rmd文件中使用knit2pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:19