These functions assist with updating or adding column headers (modify_header()), footnotes (modify_footnote()), and spanning headers (modify_spanning_header()). Use show_header_names() to learn the column names.

modify_header(
  x,
  update = NULL,
  stat_by = NULL,
  text_interpret = c("md", "html"),
  ...
)

modify_footnote(x, update, abbreviation = FALSE)

modify_spanning_header(x, update)

show_header_names(x = NULL, quiet = NULL)

Arguments

x

a gtsummary object

update

list of formulas or a single formula specifying the updated column header, footnote, or spanning header. The LHS specifies the column(s) to be updated, and the RHS is the updated text. Use the show_header_names() to see the column names that can be modified.

stat_by

Used with tbl_summary(by=) objects with a by= argument. String specifying text to include above the summary statistics. The following fields are available for use in the headers:

  • {n} number of observations in each group,

  • {N} total number of observations,

  • {p} percentage in each group,

  • {level} the 'by' variable level,

Syntax follows glue::glue(), e.g. stat_by = "**{level}**, N = {n} ({style_percent(p)}%)".

text_interpret

String indicates whether text will be interpreted with gt::md() or gt::html(). Must be "md" (default) or "html".

...

Specify a column and updated column label, e.g. modify_header(p.value = "Model P-values"). This is provided as an alternative to the update= argument. They accomplish the same goal of updating column headers.

abbreviation

Logical indicating if an abbreviation is being updated.

quiet

Logical indicating whether to print messages in console. Default is FALSE

Value

Updated gtsummary object

Example Output

Example 1

Example 2

Example 3

See also

Author

Daniel D. Sjoberg

Examples

# create summary table tbl <- trial[c("age", "grade", "trt")] %>% tbl_summary(by = trt, missing = "no") %>% add_p() # print the column names that can be modified show_header_names(tbl)
#> #> #> Column Name Column Header #> ------------ -------------------- #> label **Characteristic** #> stat_1 **Drug A**, N = 98 #> stat_2 **Drug B**, N = 102 #> p.value **p-value** #>
#> As a usage guide, the code below re-creates the current column headers.
#> modify_header(update = list( #> label ~ '**Characteristic**', #> stat_1 ~ '**Drug A**, N = 98', #> stat_2 ~ '**Drug B**, N = 102', #> p.value ~ '**p-value**' #> ))
# Example 1 ---------------------------------- # updating column headers and footnote modify_ex1 <- tbl %>% modify_header( update = list(label ~ "**Variable**", p.value ~ "**P**") ) %>% modify_footnote( update = starts_with("stat_") ~ "median (IQR) for Age; n (%) for Grade" ) # Example 2 ---------------------------------- # using `stat_by=` argument to update headers, remove all footnotes, add spanning header modify_ex2 <- tbl %>% modify_header(stat_by = "**{level}**, N = {n} ({style_percent(p)}%)") %>% # use `modify_footnote(everything() ~ NA, abbreviation = TRUE)` to delete abbrev. footnotes modify_footnote(update = everything() ~ NA) %>% modify_spanning_header(starts_with("stat_") ~ "**Treatment Received**") # Example 3 ---------------------------------- # updating an abbreviation in table footnote modify_ex3 <- glm(response ~ age + grade, trial, family = binomial) %>% tbl_regression(exponentiate = TRUE) %>% modify_footnote(ci ~ "CI = Credible Interval", abbreviation = TRUE)