Add or remove the numbered footnotes of a table.
modify_footnote_header()andremove_footnote_header()work on column headersmodify_footnote_body()andremove_footnote_body()work on cells of the table body, including the variable labelsmodify_footnote_spanning_header()andremove_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 inmodify_header().- columns
(selector)
Columns to attach the footnote to. Formodify_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 ofx$table_body, e.g.variable == "grade" & row_type == "label". Theremove_footnote_body()defaultTRUEselects every row.- level
(
integer)
The level of the spanning header.
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().
See also
modify_source_note() and modify_abbreviation() for notes
without a marker; the
modifier functions article
compares footnotes, source notes and abbreviations.
Other modify and format:
add_variable_group_header(),
bold_italicize_labels_levels,
bold_p(),
modify_abbreviation(),
modify_caption(),
modify_header(),
modify_source_note(),
remove_row_type(),
separate_p_footnotes(),
sort_p()
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())