【问题标题】:Setting knitr to output separate images设置 knitr 以输出单独的图像
【发布时间】:2017-04-16 16:35:18
【问题描述】:

我正在尝试将来自 knitr 输出的 PNG 图作为单独的文件写入磁盘,而无需手动执行。

我尝试了什么

都没有用。运行编织过程的文件夹没有多余的文件,HTML 文档的源代码中嵌入了 base64 图像。

环境

  • RStudio 0.99.903
  • R 3.2.3
  • knitr 1.15.1

MWE:RStudio RMarkdown 文件,添加了上述选项:

---
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.

【问题讨论】:

    标签: r png knitr


    【解决方案1】:

    self_containedhtml_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)
    ```
    

    【讨论】:

      猜你喜欢
      • 2017-02-28
      • 2016-01-08
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 2014-10-30
      • 1970-01-01
      • 2020-03-25
      相关资源
      最近更新 更多