quarto_chunks | R Documentation |
Generates Quarto Markdown (.qmd
) file snippets with knitr figure or table code chunks from structured data
.
quarto_chunks(data, env = parent.frame())
data |
Input data as returned by |
env |
Environment to evaluate iterations in (see section Iteration variables for details). |
The generated .qmd
files are intended to be included in other Quarto documents via the built-in
include
shortcode.
data
, invisibly.
data
All data
columns of type character are cli::pluralize()
d, meaning literal curly brackets ({
and }
) need to be escaped by doubling them (to {{
and
}}
).
The column names of data
can either correspond to quarto_fig_chunk()
/quarto_tbl_chunk()
's argument names (in snake case), to knitr's figure chunk option names (period-separared) or
directly to Quarto's
figure/table code
chunk option names (in kebab case) – they will be converted as needed.
Additional column names are silently ignored, except for the optional iteration variable columns itr_vars
(of type list) and itr_vars_r
(of type
character).
Specifying iteration variables allows to produce multiple code chunks per data
row. The iteration variables can be referred to in the other columns via
cli::pluralize()
's string interpolation syntax (i.e. R code in curly brackets).
The itr_vars
column must be a list of named lists (or NULL
for no iteration on the respective rows). The itr_vars_r
column allows to specify itr_vars
as a string of R code (which must yield a list of named lists / NULL
s when parsed and executed).
Other Quarto functions:
quarto_fig_chunk()
,
quarto_tbl_chunk()
,
read_quarto_chunk_data()
# data row without iterations
tibble::tibble(label = "fig-cars",
fig_cap = "Today's ({lubridate::today()}) top figure",
fig_column = "page",
fig_height = 8L,
body = "plot(cars)") |>
salim::quarto_chunks()
# data row with iteration variables specified directly as `itr_vars`
tibble::tibble(itr_vars = list(list(v = "cyl"),
list(v = "disp"),
list(v = "hp")),
label = "fig-mpg-by-{v}",
fig_cap = "Motor Trend Car Road Tests: mpg per {v}",
fig_column = "screen",
fig_height = 8L,
body = "plot(x = mtcars$mpg, y = mtcars${v})") |>
salim::quarto_chunks()
# data row with iteration variables specified indirectly as `itr_vars_r` code
tibble::tibble(itr_vars_r = "purrr::map(colnames(mtcars)[5:7], \\(x) list(v = x))",
label = "fig-mpg-by-{v}",
fig_cap = "Motor Trend Car Road Tests: mpg per {v}",
fig_column = "screen",
fig_height = 8L,
body = "plot(x = mtcars$mpg, y = mtcars${v})") |>
salim::quarto_chunks()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.