Printing an ltsummary object converts it with as_lt() and prints the lt
table: in an interactive session it opens in the viewer, and in knitr, R
Markdown, Quarto and litedown documents it renders as HTML. The methods
for knitr::knit_print(), xfun::record_print() (litedown) and
pkgdown::pkgdown_print() are registered when those packages are loaded.
For Word, PDF or typst output from Quarto, set
options(lt.lt_static = list(fragment = TRUE, css = FALSE)) before the
first table; lt then emits a static HTML table that Quarto converts to a
native one, at the cost of indentation and bold cells. The article linked
below says what each format keeps.
The "data.frame" print engine prints the formatted data frame from
as.data.frame.ltsummary() instead, which is useful in the console and in plain
text output.
Usage
# S3 method for class 'ltsummary'
print(x, print_engine = c("lt", "data.frame"), ...)
# S3 method for class 'ltsummary'
format(x, fragment = TRUE, inline_assets = TRUE, assets = TRUE, ...)
# S3 method for class 'ltsummary'
knit_print(x, ...)
# S3 method for class 'ltsummary'
record_print(x, ...)
# S3 method for class 'ltsummary'
pkgdown_print(x, visible = TRUE)Arguments
- x
(
ltsummary)
An ltsummary object.- print_engine
(
string)"lt"(the default) or"data.frame". The default can be changed withoptions(ltsummary.print_engine = "data.frame").- ...
Passed to the underlying print method.
- fragment, inline_assets, assets
- visible
(
scalar logical)
Whether the value was visible.
See also
The Quarto and R Markdown article for output formats.
Other output:
as.data.frame.ltsummary(),
as_lt(),
inline_text()
Examples
tbl <- trial |>
tbl_summary(by = trt, include = c(age, grade))
# Example 1 ----------------------------------
# in the console, or when no browser is at hand
print(tbl, print_engine = "data.frame")
#> **Characteristic** **Drug A** \nN = 95 **Drug B** \nN = 105
#> Age 59 (51, 66) 62 (54, 71)
#> Unknown 4 7
#> Grade <NA> <NA>
#> I 25 (26%) 37 (35%)
#> II 40 (42%) 43 (41%)
#> III 30 (32%) 25 (24%)
# Example 2 ----------------------------------
# the HTML behind the rendered table
substr(format(tbl), 1, 60)
#> <style>
#> th, td{ padding: 5px; }
#> .lt-wrap { overflow-x: auto;
# \donttest{
# Example 3 ----------------------------------
# the default: open the table in the viewer
tbl
# }