Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

modify

Modify column headers, footnotes, spanning headers, and table captions


Description

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

Usage

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

modify_footnote(
  x,
  update = NULL,
  abbreviation = FALSE,
  text_interpret = c("md", "html"),
  quiet = NULL
)

modify_spanning_header(
  x,
  update = NULL,
  text_interpret = c("md", "html"),
  quiet = NULL
)

modify_caption(x, caption, text_interpret = c("md", "html"))

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.

text_interpret

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

quiet

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

...

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.

stat_by

DEPRECATED, use update = all_stat_cols() ~ "<label>" instead.

abbreviation

Logical indicating if an abbreviation is being updated.

caption

a string of the table caption/title

Value

Updated gtsummary object

tbl_summary(), tbl_svysummary(), and tbl_cross()

When assigning column headers, footnotes, spanning headers, and captions for these gtsummary tables, you may use {N} to insert the number of observations. tbl_svysummary objects additionally have {N_unweighted} available.

When there is a stratifying by= argument present, the following fields are additionally available to stratifying columns: {level}, {n}, and {p} ({n_unweighted} and {p_unweighted} for tbl_svysummary objects)

Syntax follows glue::glue(), e.g. all_stat_cols() ~ "**{level}**, N = {n}".

tbl_regression()

When assigning column headers for tbl_regression tables, you may use {N} to insert the number of observations, and {N_event} for the number of events (when applicable).

captions

Captions are assigned based on output type.

  • gt::gt(caption=), available in gt version >0.2.2

  • flextable::set_caption(caption=)

  • huxtable::set_caption(value=)

  • knitr::kable(caption=)

Example Output

Example 1

Example 2

Example 3

Author(s)

Daniel D. Sjoberg

See Also

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)

# Example 1 ----------------------------------
# updating column headers, footnote, and table caption
modify_ex1 <- tbl %>%
  modify_header(
    update = list(
      label ~ "**Variable**",
      p.value ~ "**P**"
    )
  ) %>%
  modify_footnote(
    update = all_stat_cols() ~ "median (IQR) for Age; n (%) for Grade"
  ) %>%
  modify_caption("**Patient Characteristics** (N = {N})")

# Example 2 ----------------------------------
# updating headers, remove all footnotes, add spanning header
modify_ex2 <- tbl %>%
  modify_header(update = all_stat_cols() ~ "**{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(all_stat_cols() ~ "**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)

gtsummary

Presentation-Ready Data Summary and Analytic Result Tables

v1.4.0
MIT + file LICENSE
Authors
Daniel D. Sjoberg [aut, cre] (<https://orcid.org/0000-0003-0862-2018>), Michael Curry [aut] (<https://orcid.org/0000-0002-0261-4044>), Margie Hannum [aut] (<https://orcid.org/0000-0002-2953-0449>), Joseph Larmarange [aut] (<https://orcid.org/0000-0001-7097-700X>), Karissa Whiting [aut] (<https://orcid.org/0000-0002-4683-1868>), Emily C. Zabor [aut] (<https://orcid.org/0000-0002-1402-4498>), Esther Drill [ctb] (<https://orcid.org/0000-0002-3315-4538>), Jessica Flynn [ctb] (<https://orcid.org/0000-0001-8310-6684>), Jessica Lavery [ctb] (<https://orcid.org/0000-0002-2746-5647>), Stephanie Lobaugh [ctb], Gustavo Zapata Wainberg [ctb] (<https://orcid.org/0000-0002-2524-3637>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.