Skip to contents

Usage

tbl_chunk(
  body,
  label,
  tbl_cap,
  tbl_subcap = NULL,
  tbl_cap_location = NULL,
  tbl_colwidths = NULL,
  tbl_column = NULL,
  column = NULL,
  layout_ncol = NULL,
  layout_nrow = NULL,
  layout = 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 "tbl-" and only contains letters, numbers, underscores (_) and dashes (-).

tbl_cap

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

tbl_subcap

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

tbl_cap_location

Location to place table captions. Set as Quarto's tbl-cap-location code chunk option. Either NULL to omit or one of "top", "bottom" or "margin".

tbl_colwidths

Apply explicit table column widths for Markdown grid tables and pipe tables that are more than columns characters wide (72 by default).

Some formats (e.g. HTML) do an excellent job automatically sizing table columns and so don’t benefit much from column width specifications. Other formats (e.g. LaTeX) require table column sizes in order to correctly flow longer cell content (this is a major reason why tables > 72 columns wide are assigned explicit widths by Pandoc).

This can be specified as:

  • "auto": Apply Markdown table column widths except when there is a hyperlink in the table (which tends to throw off automatic calculation of column widths based on the Markdown text width of cells). "auto" is the default for HTML output formats.

  • "true": Always apply Markdown table widths. "true" is the default for all non-HTML formats.

  • "false": Never apply Markdown table widths.

  • A numeric vector (e.g. c(40, 30, 30)): Array of explicit width percentages.

  • NULL to omit the tbl-colwidths chunk option.

tbl_column

Quarto article layout class for the figure output. Set as Quarto's tbl-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"

  • "page-inset-left"

  • "page-inset-right"

  • "screen"

  • "screen-left"

  • "screen-right"

  • "screen-inset"

  • "screen-inset-shaded"

  • "screen-inset-left"

  • "screen-inset-right"

  • "margin"

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"

  • "page-inset-left"

  • "page-inset-right"

  • "screen"

  • "screen-left"

  • "screen-right"

  • "screen-inset"

  • "screen-inset-shaded"

  • "screen-inset-left"

  • "screen-inset-right"

  • "margin"

layout_ncol

Number of columns to arrange the chunk output in. Set as Quarto's layout-ncol code chunk option. Either NULL to omit or a positive integerish number.

layout_nrow

Number of rows to arrange the chunk output in. Set as Quarto's layout-nrow code chunk option. Either NULL to omit or a positive integerish number.

layout

Custom layout proportions. Set as Quarto's layout code chunk option. A list of numeric vectors where each vector defines the column proportions of a row. Note that the numbers in a row are arbitrary and don’t need to add up to a particular total.

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(), fig_chunk(), read_chunk_toml()

Examples

quappo::tbl_chunk(body = "knitr::kable(head(cars))",
                  label = "tbl-head-cars",
                  tbl_cap = "Head of dataset `cars`",
                  tbl_column = "margin")
#> ```{r}
#> #| label: tbl-head-cars
#> #| tbl-cap:
#> #|   - Head of dataset `cars`
#> #| tbl-column: margin
#> 
#> knitr::kable(head(cars))
#> ```
#>