Skip to contents

Add or remove the numbered footnotes of a table.

  • modify_footnote_header() and remove_footnote_header() work on column headers

  • modify_footnote_body() and remove_footnote_body() work on cells of the table body, including the variable labels

  • modify_footnote_spanning_header() and remove_footnote_spanning_header() work on spanning headers

Footnotes are numbered in the order they appear in the table, from top left to bottom right, and a footnote that appears in several places is listed once. By default a new footnote replaces any footnote already attached to the same location; pass replace = FALSE to keep the existing ones.

Usage

modify_footnote_header(
  x,
  footnote,
  columns,
  replace = TRUE,
  text_interpret = c("md", "html", "none")
)

modify_footnote_body(
  x,
  footnote,
  columns,
  rows,
  replace = TRUE,
  text_interpret = c("md", "html", "none")
)

modify_footnote_spanning_header(
  x,
  footnote,
  columns,
  level = 1L,
  replace = TRUE,
  text_interpret = c("md", "html", "none")
)

remove_footnote_header(x, columns = everything())

remove_footnote_body(x, columns = everything(), rows = TRUE)

remove_footnote_spanning_header(x, columns = everything(), level = 1L)

Arguments

x

(ltsummary)
An ltsummary object.

footnote

(string)
The footnote text. The dynamic values of the column, {N}, {n}, {p} and {level}, can be used as in modify_header().

columns

(selector)
Columns to attach the footnote to. For modify_footnote_spanning_header(), the spanning header covering the first selected column is used.

replace

(scalar logical)
Whether the footnote replaces existing footnotes at the same location (TRUE, the default) or is added to them.

text_interpret

(string)
How the text is interpreted: "md" (the default; the markdown subset **bold**, _italic_ and line breaks), "html" (raw HTML) or "none" (shown verbatim).

rows

(predicate expression)
Expression selecting rows of x$table_body, e.g. variable == "grade" & row_type == "label". The remove_footnote_body() default TRUE selects every row.

level

(integer)
The level of the spanning header.

Value

An ltsummary object.

rows argument

The rows argument is a predicate expression that selects the rows the styling applies to. It is evaluated in x$table_body, so its column names are available as variables, and it must give a logical vector. To style the rows of the age variable pass rows = variable == "age"; to style the variable label rows pass rows = row_type == "label". A logical vector, a vector of row numbers or a function of table_body are also accepted.

Objects from the calling environment can be used in the expression, e.g. rows = variable == vars[1], as long as they do not share a name with a column of x$table_body. The expression is stored, not its result, and resolved when the table is printed, so it survives later changes to the table such as remove_row_type().

Examples

# Example 1 ----------------------------------
tbl <- trial |>
  tbl_summary(by = trt, include = c(age, grade), missing = "no") |>
  modify_footnote_header(
    footnote = "All but four subjects received both treatments in a crossover design",
    columns = all_stat_cols(),
    replace = FALSE
  ) |>
  modify_footnote_body(
    footnote = "Tumor grade was assessed _before_ treatment began",
    columns = "label",
    rows = variable == "grade" & row_type == "label"
  )
tbl
# Example 2 ---------------------------------- # remove the two footnotes again tbl |> remove_footnote_header(columns = all_stat_cols()) |> remove_footnote_body(columns = label, rows = variable == "grade" & row_type == "label")
# Example 3 ---------------------------------- # a footnote on a spanning header, with the total N filled in trial |> tbl_summary(by = trt, include = c(age, grade), missing = "no") |> modify_spanning_header(all_stat_cols() ~ "**Treatment Received**") |> modify_footnote_spanning_header("Randomized 1:1, N = {N}", columns = all_stat_cols())