| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/utils.R |
| 3 |
\name{fig_chunk} |
| 4 |
\alias{fig_chunk} |
| 5 |
\title{Obtain the figure filenames for a chunk} |
| 6 |
\usage{ |
| 7 |
fig_chunk(label, ext = "", number, fig.path = opts_chunk$get("fig.path")) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{label}{The chunk label.} |
| 11 |
|
| 12 |
\item{ext}{The figure file extension, e.g. \code{png} or \code{pdf}.} |
| 13 |
|
| 14 |
\item{number}{The figure number (by default \code{1}).} |
| 15 |
|
| 16 |
\item{fig.path}{Passed to \code{\link{fig_path}}. By default, the chunk |
| 17 |
option \code{fig.path} is used.} |
| 18 |
} |
| 19 |
\value{ |
| 20 |
A character vector of filenames. |
| 21 |
} |
| 22 |
\description{ |
| 23 |
Given a chunk label, the figure file extension, the figure number(s), and the |
| 24 |
chunk option \code{fig.path}, return the filename(s). |
| 25 |
} |
| 26 |
\details{ |
| 27 |
This function can be used in an inline R expression to write out the figure |
| 28 |
filenames without hard-coding them. For example, if you created a plot in a |
| 29 |
code chunk with the label \code{foo} and figure path \file{my-figure/}, you |
| 30 |
are not recommended to use hard-coded figure paths like |
| 31 |
\samp{\includegraphics{my-figure/foo-1.pdf}} (in \file{.Rnw} documents) or |
| 32 |
\samp{} (R Markdown) in your document. Instead, you |
| 33 |
should use \samp{\\Sexpr{fig_chunk('foo', 'pdf')}} or \samp{`)}. |
| 35 |
|
| 36 |
You can generate plots in a code chunk but not show them inside the code |
| 37 |
chunk by using the chunk option \code{fig.show = 'hide'}. Then you can use |
| 38 |
this function if you want to show them elsewhere. |
| 39 |
} |
| 40 |
\examples{ |
| 41 |
library(knitr) |
| 42 |
fig_chunk("foo", "png") |
| 43 |
fig_chunk("foo", "pdf") |
| 44 |
fig_chunk("foo", "svg", 2) # the second plot of the chunk foo |
| 45 |
fig_chunk("foo", "png", 1:5) # if the chunk foo produced 5 plots |
| 46 |
} |