Skip to contents

Converts an ltsummary object to an "lt_tbl" object, that is, a table created with lt::lt(). The function runs in the background when a table is printed or knit. Call it yourself to add the formatting available in the lt package: the result accepts any lt::lt_*() function, for example lt::lt_width() to set the table width or lt::lt_export() to save the table as HTML, PDF or PNG.

The conversion translates the table body and every styling instruction (header labels, spanning headers, footnotes, source notes, abbreviations, bold and italic text, indentation, missing-value symbols, merged columns) into a sequence of lt calls. as_lt(return_calls = TRUE) returns that sequence, and include drops calls from it.

Usage

as_lt(x, include = everything(), return_calls = FALSE, css = NULL, ...)

Arguments

x

(ltsummary)
An ltsummary object.

include

(selector)
The lt calls to include, selected by name, e.g. include = -lt_align to keep lt's default alignment. The "lt" call is always included. Run names(as_lt(x, return_calls = TRUE)) to see the names. Default is everything().

return_calls

(scalar logical)
When TRUE, the list of unevaluated lt calls is returned instead of the table. Default is FALSE.

css

(character)
Optional paths or URLs of stylesheets, passed to lt::lt_css().

...

Not used.

Value

An lt_tbl object, or a named list of calls when return_calls = TRUE.

See also

The Quarto and R Markdown article for output formats and saving tables.

Other output: as.data.frame.ltsummary(), inline_text(), print.ltsummary()

Examples

# Example 1 ----------------------------------
tbl <- trial |>
  tbl_summary(by = trt, include = c(age, grade, response))
as_lt(tbl)

# Example 2 ----------------------------------
# keep customizing with lt functions
as_lt(tbl) |>
  lt::lt_width("60%") |>
  lt::lt_note("Data are simulated")

# Example 3 ----------------------------------
# the lt calls behind the table, and dropping one of them
names(as_lt(tbl, return_calls = TRUE))
#> [1] "lt"          "lt_label"    "lt_align"    "lt_align_2"  "lt_footnote"
#> [6] "lt_indent"  
as_lt(tbl, include = -lt_align)