gpt4 book ai didi

r - 在Rmd文件中使用knit2pdf

转载 作者:行者123 更新时间:2023-12-04 07:52:59 24 4
gpt4 key购买 nike

是否可以将Rnitdown(Rmd)文件直接使用knitr函数knit2pdf()?我看过各种教程/类笔记,似乎暗示它可以例如herehere(两者均为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 

帮助极大的赞赏。

最佳答案

您的输入文件为rmarkdown格式。

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

尝试:

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

关于r - 在Rmd文件中使用knit2pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com