我正在尝试从knitr输出中获取PNG图,以便将其作为单独的文件写入磁盘,而无需手动执行。
dev = 'png'
设置(this question中也提及)self_contained: no
。都没有奏效。编织进程运行的文件夹没有额外的文件,HTML文档的源代码中有base64嵌入的图像。
---
title: "Untitled"
output: html_document
self_contained: no
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(dev="png",
dev.args=list(type="cairo"),
dpi=96)
```
## R Markdown
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 cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
答案 0 :(得分:3)
self_contained
是html_document
的选项,而不是顶级YAML设置。下面的文档仅使用它。 PNG是默认的数字类型,因此您无需指定。
---
title: "Untitled"
output:
html_document:
self_contained: no
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```