fig_chunk

0th

Percentile

Obtain the figure filenames for a chunk

Given a chunk label, the figure file extension, the figure number(s), and the chunk option fig.path, return the filename(s).

Usage
fig_chunk(label, ext = "", number, fig.path = opts_chunk$get("fig.path"))
Arguments
label

the chunk label

ext

the figure file extension, e.g. png or pdf

number

the figure number (by default 1)

fig.path

the chunk option fig.path

Details

This function can be used in an inline R expression to write out the figure filenames without hard-coding them. For example, if you created a plot in a code chunk with the label foo and figure path my-figure/, you are not recommended to use hard-coded figure paths like \includegraphics{my-figure/foo-1.pdf} (in .Rnw documents) or ![](my-figure/foo-1.png) (R Markdown) in your document. Instead, you should use \Sexpr{fig_chunk('foo', 'pdf')} or ![](`r fig_chunk('foo', 'png')`).

You can generate plots in a code chunk but not show them inside the code chunk by using the chunk option fig.show = 'hide'. Then you can use this function if you want to show them elsewhere.

Value

A character vector of filenames.

Aliases
  • fig_chunk
Examples
# NOT RUN {
library(knitr)
fig_chunk("foo", "png")
fig_chunk("foo", "pdf")
fig_chunk("foo", "svg", 2)  # the second plot of the chunk foo
fig_chunk("foo", "png", 1:5)  # if the chunk foo produced 5 plots
# }
Documentation reproduced from package knitr, version 1.16, License: GPL

Community examples

Looks like there are no examples yet.