Skip to contents

[Stable]

Formatting function for the majority of default methods used in analyze_vars(). For non-derived values, the significant digits of data is used (e.g. range), while derived values have one more digits (measure of location and dispersion like mean, standard deviation). This function can be called internally with "auto" like, for example, .formats = c("mean" = "auto"). See details to see how this works with the inner function.

Usage

format_auto(dt_var, x_stat)

Arguments

dt_var

(numeric)
all the data the statistics was created upon. Used only to find significant digits. In analyze_vars this comes from .df_row (see rtables::additional_fun_params), and it is the row data after the above row splits. No column split is considered.

x_stat

(string)
string indicating the current statistical method used.

Value

A string that rtables prints in a table cell.

Details

The internal function is needed to work with rtables default structure for format functions, i.e. function(x, ...), where is x are results from statistical evaluation. It can be more than one element (e.g. for .stats = "mean_sd").

Examples

x_todo <- c(0.001, 0.2, 0.0011000, 3, 4)
res <- c(mean(x_todo[1:3]), sd(x_todo[1:3]))

# x is the result coming into the formatting function -> res!!
format_auto(dt_var = x_todo, x_stat = "mean_sd")(x = res)
#> [1] "0.06737 (0.11486)"
format_auto(x_todo, "range")(x = range(x_todo))
#> [1] "0.0010 - 4.0000"
no_sc_x <- c(0.0000001, 1)
format_auto(no_sc_x, "range")(x = no_sc_x)
#> [1] "0.0000001 - 1.0000000"