# include_graphics

0th

Percentile

##### Embed external images in knitr documents

When plots are not generated from R code, there is no way for knitr to capture plots automatically. In this case, you may generate the images manually and pass their file paths to this function to include them in the output. The major advantage of using this function is that it is portable in the sense that it works for all document formats that knitr supports, so you do not need to think if you have to use, for example, LaTeX or Markdown syntax, to embed an external image. Chunk options related to graphics output that work for normal R plots also work for these images, such as out.width and out.height.

##### Usage
include_graphics(path, auto_pdf = getOption("knitr.graphics.auto_pdf", FALSE),
dpi = NULL)
##### Arguments
path

A character vector of image paths.

auto_pdf

Boolean; whether to use PDF images automatically when the output format is LaTeX. If TRUE, then e.g. foo/bar.png will be replaced by foo/bar.pdf if the latter exists. This can be useful since normally PDF images are of higher quality than raster images like PNG, when the output is LaTeX/PDF.

dpi

DPI (dots per inch) value. Used to calculate the output width (in inches) of the images. This will be their actual width in pixels, divided by dpi. If not provided, the chunk option dpi is used; if NA, the output width will not be calculated.

##### Value

The same as the input character vector path but it is marked with special internal S3 classes so that knitr will convert the file paths to proper output code according to the output format.

##### Note

This function is supposed to be used in R code chunks or inline R code expressions. You are recommended to use forward slashes (/) as path separators instead of backslashes in the image paths.

The automatic calculation of the output width requires the png package (for PNG images) or the jpeg package (for JPEG images). The width will not be calculated if the chunk option out.width is already provided or dpi = NA.

##### Aliases
• include_graphics
Documentation reproduced from package knitr, version 1.22, License: GPL

### Community examples

tertra at Feb 14, 2019 knitr v1.21

include_graphics("https://cran.r-project.org/Rlogo.svg") should be used in R code chunks  {r, out.width = "50%", fig.pos="h"} include_graphics("https://cran.r-project.org/Rlogo.svg") 

tertra at Feb 14, 2019 knitr v1.21

{r, out.width = "50%", fig.pos="h"} include_graphics("https://cran.r-project.org/Rlogo.svg")