Skip to contents

Ingests a data frame and adds the infrastructure around it to make it an ltsummary object, so that the modify_*() and bold_*() functions, as_lt() and the print methods can be used with it. Every column is shown and labelled with its label attribute or its name, and a column named label is left-aligned.

Usage

as_ltsummary(table_body, ...)

Arguments

table_body

(data.frame)
A data frame that becomes the table_body of the object.

...

Other objects added to the ltsummary list, such as inputs or call_list.

Value

An object of class "ltsummary": a list with elements table_body and table_styling, plus anything passed through ....

See also

The object definition article describes table_body and table_styling.

Other building blocks: modify_table_body(), modify_table_styling()

Examples

# Example 1 ----------------------------------
data.frame(label = c("Age", "Grade"), stat_0 = c("47 (38, 57)", "62 (31%)")) |>
  as_ltsummary()
# Example 2 ---------------------------------- # a data frame of results, styled with the modifier functions df <- data.frame( label = c("Age", "Marker"), estimate = c(1.234, -0.567), conf.low = c(0.9, -1.1), conf.high = c(1.6, 0.02), p.value = c(0.0004, 0.21) ) as_ltsummary(df) |> modify_header( label = "**Variable**", estimate = "**Beta**", conf.low = "**95% CI**", p.value = "**p-value**" ) |> modify_fmt_fun( c(estimate, conf.low, conf.high) ~ label_style_sigfig(), p.value = label_style_pvalue() ) |> modify_column_merge(pattern = "{conf.low}, {conf.high}") |> modify_abbreviation("CI = Confidence Interval") |> bold_p()