| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/plot.R |
| 3 |
\name{include_graphics} |
| 4 |
\alias{include_graphics} |
| 5 |
\title{Embed external images in \pkg{knitr} documents} |
| 6 |
\usage{ |
| 7 |
include_graphics( |
| 8 |
path, |
| 9 |
auto_pdf = getOption("knitr.graphics.auto_pdf", FALSE), |
| 10 |
dpi = NULL, |
| 11 |
rel_path = getOption("knitr.graphics.rel_path", TRUE), |
| 12 |
error = getOption("knitr.graphics.error", TRUE) |
| 13 |
) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{path}{A character vector of image paths. Both local file paths and web |
| 17 |
paths are supported. Note that the \code{auto_pdf} and \code{dpi} arguments |
| 18 |
are not supported for web paths.} |
| 19 |
|
| 20 |
\item{auto_pdf}{Whether to use PDF images automatically when the output |
| 21 |
format is LaTeX. If \code{TRUE}, then e.g. \file{foo/bar.png} will be |
| 22 |
replaced by \file{foo/bar.pdf} if the latter exists. This can be useful |
| 23 |
since normally PDF images are of higher quality than raster images like |
| 24 |
PNG, when the output is LaTeX/PDF.} |
| 25 |
|
| 26 |
\item{dpi}{DPI (dots per inch) value. Used to calculate the output width (in |
| 27 |
inches) of the images. This will be their actual width in pixels, divided |
| 28 |
by \code{dpi}. If not provided, the chunk option \code{dpi} is used; if |
| 29 |
\code{NA}, the output width will not be calculated.} |
| 30 |
|
| 31 |
\item{rel_path}{Whether to automatically convert absolute paths to relative |
| 32 |
paths. If you know for sure that absolute paths work, you may set this |
| 33 |
argument or the global option \code{knitr.graphics.rel_path} to |
| 34 |
\code{FALSE}.} |
| 35 |
|
| 36 |
\item{error}{Whether to signal an error if any files specified in the |
| 37 |
\code{path} argument do not exist and are not web resources.} |
| 38 |
} |
| 39 |
\value{ |
| 40 |
The same as the input character vector \code{path} but it is marked |
| 41 |
with special internal S3 classes so that \pkg{knitr} will convert the file |
| 42 |
paths to proper output code according to the output format. |
| 43 |
} |
| 44 |
\description{ |
| 45 |
When plots are not generated from R code, there is no way for \pkg{knitr} to |
| 46 |
capture plots automatically. In this case, you may generate the images |
| 47 |
manually and pass their file paths to this function to include them in the |
| 48 |
output. The major advantage of using this function is that it is portable in |
| 49 |
the sense that it works for all document formats that \pkg{knitr} supports, |
| 50 |
so you do not need to think if you have to use, for example, LaTeX or |
| 51 |
Markdown syntax, to embed an external image. Chunk options related to |
| 52 |
graphics output that work for normal R plots also work for these images, such |
| 53 |
as \code{out.width} and \code{out.height}. |
| 54 |
} |
| 55 |
\note{ |
| 56 |
This function is supposed to be used in R code chunks or inline R code |
| 57 |
expressions. For local images, you are recommended to use relative paths |
| 58 |
with forward slashes instead of backslashes (e.g., \file{images/fig1.png} |
| 59 |
instead of \file{/Users/me/code/images/fig1.png}). |
| 60 |
|
| 61 |
The automatic calculation of the output width requires the \pkg{png} |
| 62 |
package (for PNG images) or the \pkg{jpeg} package (for JPEG images). The |
| 63 |
width will not be calculated if the chunk option \code{out.width} is |
| 64 |
already provided or \code{dpi = NA}. |
| 65 |
} |