Search code examples
rr-markdownknitr

How can I knit a Rmarkdown file into a html file which embeds plots?


In a Rmd file, there are several places which generate plots, for example

```{r outliers}
influencePlot (model1)
```

I knit the file into a html file and several image files under directory ./figure/, by running in a R session

> library(knitr)
> knit("my.Rmd")

and then running in a bash session

$ pandoc my.md -f markdown -t html -s -o my.html

but the html file doesn't embed the plots from the image files, for example:

<img src="figure/outliers-1.png" alt="plot of chunk outliers" />

I was wondering how I could make the html file embed the plots from the image files and become self contained?

In RStudio, when I click "knit to html" button, it embeds the plot images in html file, for example

<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhE...

What is the equivalent commands to RStudio's "knit to html" button?


Solution

  • What is the equivalent commands to RStudio's "knit to html" button?

    Submit your output in a YAML header and then use

    rmarkdown::render("Your-RMD-file.Rmd")
    

    Or see the documentation for the render function and their arguments.