Skip to contents

Usage

fig_chunk(
  body,
  label,
  fig_cap = NULL,
  fig_subcap = NULL,
  fig_column = NULL,
  fig_width = NULL,
  fig_height = NULL,
  fig_pos = "H",
  fig_link = NULL,
  column = 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-" and only contains letters, numbers, underscores (_) and dashes (-).

fig_cap

Figure caption. Set as Quarto's fig-cap code chunk option. Either NULL to omit or a character vector.

fig_subcap

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

fig_column

Quarto article layout class for the figure output. Set as Quarto's fig-column code chunk option. Either NULL to omit or 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. Either NULL to omit or a numeric scalar.

fig_height

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

fig_pos

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

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

column

Quarto article layout class for all of the code chunk's output. Set as Quarto's column code chunk option. Either NULL to omit or 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"

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. Either NULL to omit or a character scalar.

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. Either NULL to omit or a character scalar.

Value

A character scalar.

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")

See also

Other code chunk functions: chunks(), read_chunk_toml(), tbl_chunk()

Examples

quappo::fig_chunk(body = "plot(cars)",
                  label = "fig-mtcars",
                  fig_cap = "Default plot for dataset `cars`",
                  fig_column = "page")
#> ```{r}
#> #| label: fig-mtcars
#> #| fig-cap:
#> #|   - Default plot for dataset `cars`
#> #| fig-column: page
#> #| fig-pos: H
#> 
#> plot(cars)
#> ```
#>