Open bzkrouse opened 2 months ago
From our meeting on May 20, 2024: Something like this could work for populating an Overall grouping level from within ard_shuffle()
library(cards)
tt <- bind_ard(
ard_categorical(ADSL, by = ARM, variables = AGEGR1),
ard_categorical(ADSL, variables = AGEGR1),
ard_categorical(ADSL, variables = ARM)
)
tt_missing_by <-
tt |>
dplyr::filter(is.na(group1)) |>
dplyr::rows_update(
tt |>
dplyr::filter(!is.na(group1)) |>
dplyr::select(all_ard_variables(), "stat_name", "stat_label") |>
dplyr::distinct() |>
dplyr::mutate(group1 = "ARM", group1_level = list("Overall"), .before = 1L),
by = c("variable", "variable_level", "stat_name", "stat_label"),
unmatched = "ignore"
)
tt_missing_by
tt[is.na(tt$group1), names(tt_missing_by)] <- tt_missing_by
tt
We have some code in
shuffle_ard()
to populate levels with "Overall < varname >" if a grouping variable is present but its level is NA (like with for overall stat tests). It would be nice for this to happen for overall calculations fromard_stack()
as well, to effectively create a separate "overall" category for displays. This requires adding just a bit of code inard_stack()
prior to the shuffle.example:
Current rows corresponding to the overall calculations:
Desired result:
@ddsjoberg I will put in a PR to get your thoughts!