quarto_fig_chunk: Assemble Quarto knitr figure chunk

quarto_fig_chunkR Documentation

Assemble Quarto knitr figure chunk

Description

Assembles a Quarto knitr figure chunk.

Usage

quarto_fig_chunk(
  body,
  label,
  fig_cap,
  fig_subcap = NULL,
  fig_column = "body",
  fig_width = NULL,
  fig_height = NULL,
  fig_pos = "H",
  fig_link = NULL,
  out_width = NULL,
  out_height = NULL
)

Arguments

body

R code to insert into the code chunk's body. A character scalar.

label

Unique code chunk label. Set as Quarto's label code chunk option. A character scalar that starts with "fig-".

fig_cap

Figure caption. Set as Quarto's fig-cap code chunk option. A character scalar.

fig_subcap

Figure subcaptions. Set as Quarto's fig-subcap code chunk option. A character vector, or NULL to omit.

fig_column

Quarto article layout class for the figure output. Set as Quarto's fig-column code chunk option. One of

  • "body"

  • "body-outset"

  • "body-outset-left"

  • "body-outset-right"

  • "page"

  • "page-left"

  • "page-right"

  • "page-inset-left"

  • "page-inset-right"

  • "screen"

  • "screen-left"

  • "screen-right"

  • "screen-inset"

  • "screen-inset-shaded"

  • "screen-inset-left"

  • "screen-inset-right"

  • "margin"

fig_width

Width of the plot (in inches), to be used in the graphics device. Set as Quarto's fig-width code chunk option. A numeric scalar, or NULL to omit.

fig_height

Height of the plot (in inches), to be used in the graphics device. Set as Quarto's fig-height code chunk option. A numeric scalar, or NULL to omit.

fig_pos

LaTeX figure position arrangement to be used in ⁠\begin{figure}[]⁠. Set as Quarto's fig-pos code chunk option. A character scalar, or NULL to omit. Use "false" for no figure position specifier, which is sometimes necessary with custom figure environments (such as sidewaysfigure).

fig_link

Hyperlink target for the figure. Set as Quarto's fig-link code chunk option. A character scalar, or NULL to omit.

out_width

Width of the plot in the output document, which can be different from its physical fig_width, i.e., plots can be scaled in the output document. Set as Quarto's out-width code chunk option. A character scalar, or NULL to omit.

out_height

Height of the plot in the output document, which can be different from its physical fig_height, i.e., plots can be scaled in the output document. Set as Quarto's out-height code chunk option. A character scalar, or NULL to omit.

Details

Use substitute together with deparse1() to convert R expressions to a character scalar as expected by param body:

deparse1(expr = substitute(do_something()),
         collapse = "\n")

Value

A character scalar.

See Also

Other Quarto functions: quarto_chunks(), quarto_tbl_chunk(), read_quarto_chunk_data()

Examples

salim::quarto_fig_chunk(body = "plot(cars)",
                        label = "fig-mtcars",
                        fig_cap = "Default plot for dataset `cars`",
                        fig_column = "page") |>
  cat()

salim-b/salim documentation built on May 18, 2024, 7:08 a.m.