Skip to contents

[Stable]

Constructor function which creates a combined formatted analysis function.

Usage

create_afun_compare(
  .stats = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)

Arguments

.stats

(character)
statistics to select for the table.

.formats

(named character or list)
formats for the statistics.

.labels

(named character)
labels for the statistics (without indent).

.indent_mods

(named integer)
indent modifiers for the labels.

Value

Combined formatted analysis function for use in compare_vars().

Note

Since a_compare() is generic and we want customization of the formatting arguments via rtables::make_afun(), we need to create another temporary generic function, with corresponding customized methods. Then in order for the methods to be found, we need to wrap them in a combined afun. Since this is required by two layout creating functions (and possibly others in the future), we provide a constructor that does this: create_afun_compare().

See also

Examples

# `create_afun_compare()` to create combined `afun`

afun <- create_afun_compare(
  .stats = c("n", "count_fraction", "mean_sd", "pval"),
  .indent_mods = c(pval = 1L)
)

lyt <- basic_table() %>%
  split_cols_by("ARMCD", ref_group = "ARM A") %>%
  analyze(
    "AGE",
    afun = afun,
    show_labels = "visible"
  )
build_table(lyt, df = tern_ex_adsl)
#>                          ARM A        ARM B        ARM C   
#> ———————————————————————————————————————————————————————————
#> AGE                                                        
#>   n                        69           73           58    
#>   Mean (SD)            34.1 (6.8)   35.8 (7.1)   36.1 (7.4)
#>     p-value (t-test)                  0.1446       0.1176  

lyt <- basic_table() %>%
  split_cols_by("ARMCD", ref_group = "ARM A") %>%
  analyze(
    "SEX",
    afun = afun,
    show_labels = "visible"
  )
build_table(lyt, df = tern_ex_adsl)
#>                                    ARM A        ARM B        ARM C   
#> —————————————————————————————————————————————————————————————————————
#> SEX                                                                  
#>   n                                  69           73           58    
#>   F                              38 (55.1%)   40 (54.8%)   32 (55.2%)
#>   M                              31 (44.9%)   33 (45.2%)   26 (44.8%)
#>     p-value (chi-squared test)                  1.0000       1.0000