Use this function to update the way numeric columns and rows of .$table_body
are formatted
Arguments
- x
(
gtsummary)
A gtsummary object- ...
dynamic-dots
Used to assign updates to formatting functions.Use
modify_fmt_fun(colname = <fmt fun>)to update a single column. Using a formula will invoke tidyselect, e.g.modify_fmt_fun(c(estimate, conf.low, conf.high) ~ <fmt_fun>).Use the
show_header_names()to see the column names that can be modified.- rows
(predicate
expression)
Predicate expression to select rows inx$table_body. Can be used to style footnote, formatting functions, missing symbols, and text formatting. Default isNULL. See details below.- update, quiet
rows argument
The rows argument accepts a predicate expression that is used to specify
rows to apply formatting. The expression must evaluate to a logical when
evaluated in x$table_body. For example, to apply formatting to the age rows
pass rows = variable == "age". A vector of row numbers is NOT acceptable.
A couple of things to note when using the rows argument.
You can use saved objects to create the predicate argument, e.g.
rows = variable == letters[1].The saved object cannot share a name with a column in
x$table_body. The reason for this is that intbl_merge()the columns are renamed, and the renaming process cannot disambiguate thevariablecolumn from an external object namedvariablein the following expressionrows = .data$variable = .env$variable.
Examples
# Example 1 ----------------------------------
# show 'grade' p-values to 3 decimal places and estimates to 4 sig figs
lm(age ~ marker + grade, trial) |>
tbl_regression() %>%
modify_fmt_fun(
p.value = label_style_pvalue(digits = 3),
c(estimate, conf.low, conf.high) ~ label_style_sigfig(digits = 4),
rows = variable == "grade"
)
Characteristic
Beta
95% CI
p-value
Abbreviation: CI = Confidence Interval
