All abbreviations will be coalesced when printing the final table into a single specialized source note.
Usage
modify_abbreviation(
x,
abbreviation,
text_interpret = c("md", "html", "none"),
prefix = NULL,
sep1 = NULL,
sep2 = NULL
)
remove_abbreviation(x, abbreviation = NULL)Arguments
- x
(
gtsummary)
A gtsummary object- abbreviation
(
character)
a character vector of one or more abbreviations to add. Inremove_abbreviation(), the default value isNULL, which will remove all abbreviation source notes; otherwise a character vector of abbreviations to remove.- text_interpret
(
string)
String indicates whether text will be interpreted withgt::md()orgt::html(). Must be"md"(default),"html", or"none"."none"applies no interpretation, rendering the text verbatim (useful when the text contains markdown-significant characters). Applies to tables printed with{gt}.- prefix, sep1, sep2
(
character)
optional arguments controlling how the abbreviation source note is assembled aspaste0(prefix, sep1, paste(abbreviations, collapse = sep2)).prefixis a character vector of length two giving the leading text, asc(singular, plural). The first element is used when a single abbreviation is present and the second when multiple abbreviations are present. Passc("", "")to omit the leading text. Defaults toNULL, in which case the theme element"modify_abbreviation-arg:prefix"is used, falling back to the translated defaultc("Abbreviation", "Abbreviations"). Unlike the default, a user-suppliedprefixis used as-is and is not translated.sep1is a string giving the separator between the prefix and the abbreviations. Defaults toNULL, in which case the theme element"modify_abbreviation-arg:sep1"is used, falling back to the default": ". It is omitted when the resolved prefix is empty.sep2is a string giving the separator placed between abbreviations. Defaults toNULL, in which case the theme element"modify_abbreviation-arg:sep2"is used, falling back to the default", ".
Examples
# Example 1 ----------------------------------
tbl_summary(
trial,
by = trt,
include = age,
type = age ~ "continuous2"
) |>
modify_table_body(~dplyr::mutate(.x, label = sub("Q1, Q3", "IQR", x = label))) |>
modify_abbreviation("IQR = Interquartile Range")
Characteristic
Drug A
N = 98
Drug B
N = 102
Abbreviation: IQR = Interquartile Range
# Example 2 ----------------------------------
lm(marker ~ trt, trial) |>
tbl_regression() |>
remove_abbreviation("CI = Confidence Interval")
Characteristic
Beta
95% CI
p-value
# Example 3 ----------------------------------
# add multiple abbreviations at once and customize the prefix and separator
tbl_summary(
trial,
by = trt,
include = age,
type = age ~ "continuous2"
) |>
modify_table_body(~dplyr::mutate(.x, label = sub("Q1, Q3", "IQR", x = label))) |>
modify_abbreviation(
c("IQR = Interquartile Range", "SD = Standard Deviation"),
prefix = c("Key", "Keys"),
sep2 = "; "
)
Characteristic
Drug A
N = 98
Drug B
N = 102
Keys: IQR = Interquartile Range; SD = Standard Deviation
