quarto_tbl_chunk: Assemble Quarto knitr table chunk

quarto_tbl_chunkR Documentation

Assemble Quarto knitr table chunk

Description

Assembles a Quarto knitr table chunk.

Usage

quarto_tbl_chunk(
  body,
  label,
  tbl_cap,
  tbl_subcap = NULL,
  tbl_colwidths = NULL,
  tbl_column = "body"
)

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

tbl_cap

Table caption. Set as Quarto's tbl-cap code chunk option. A character scalar.

tbl_subcap

Table subcaptions. Set as Quarto's tbl-subcap code chunk option. A character vector.

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.

tbl_column

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

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_fig_chunk(), read_quarto_chunk_data()

Examples

salim::quarto_tbl_chunk(body = "knitr::kable(head(cars))",
                        label = "tbl-head-cars",
                        tbl_cap = "Head of dataset `cars`",
                        tbl_column = "margin") |>
  cat()

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