Skip to contents

For every variable, returns a named list of formatting functions keyed by statistic. Continuous statistics default to a number of decimal places guessed from the spread of the variable (the 5th to 95th percentile range: below 0.01 gives 4 decimals, below 0.1 gives 3, below 10 gives 2, below 20 gives 1, otherwise 0); integer variables get 0 decimals and dates are shown as text. Counts are formatted with style_number() and percentages with style_percent(). User-supplied integers become label_style_number() (with scale = 100 for percentages) and user-supplied functions are used as is.

Usage

assign_summary_digits(data, statistic, type, digits = NULL)

Arguments

data

(data.frame)
A data frame.

statistic

(named list)
Statistic templates keyed by variable, e.g. list(age = "{mean} ({sd})").

type

(named list)
Summary types keyed by variable.

digits

(named list)
User-specified digits keyed by variable: an integer, a vector of integers, a function, or a named list of either.

Value

A named list (by variable) of named lists (by statistic) of functions.

See also

Other summary engine: assign_summary_type()

Examples

fmt <- assign_summary_digits(
  trial,
  statistic = list(age = "{mean} ({sd})", grade = "{n} ({p}%)"),
  type = list(age = "continuous", grade = "categorical")
)
fmt$age$mean(45.678)
#> [1] "46"
fmt$grade$p(0.456)
#> [1] "46"