2

I'm trying to get the PNG plots from knitr output to write to disk as separate files without doing it manually.

What I tried

Neither worked. The folder the knitting process ran in has no extra files, and the HTML document has base64 embedded images in its source.

Environment

  • RStudio 0.99.903
  • R 3.2.3
  • knitr 1.15.1

MWE: The RStudio RMarkdown file, with abovementioned options added:

---
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.
bright-star
  • 6,016
  • 6
  • 42
  • 81

1 Answers1

3

self_contained is an option for html_document, not a top-level YAML setting. The document below works using just that. PNG is the default figure type, so you don't need to specify that.

---
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)
```
user2554330
  • 37,248
  • 4
  • 43
  • 90