Skip to content

add_overall_col does not inherit colcounts from previous split #1016

@SHAESEN2

Description

@SHAESEN2

I would like to display N=xx for a total column but this option is not available from the function:

adsl <- data.frame(
  ARM = c("Placebo", "Placebo", "Treatment A", "Treatment A", "Treatment B", "Treatment B"),
  AGE = c(25, 30, 22, 28, 19, 45),
  SEX = c("Male", "Female", "Male", "Female", "Female", "Female")
)

add_combo <- rtables::add_combo_facet(
  "Combined",
  label = "Combined",
  levels = c("Treatment A", "Treatment B")
)

rm_combo_from_placebo <- cond_rm_facets(
  facets = "Combined",
  ancestor_pos = NA,
  value = " ",
  split = "ARM"
)

mysplit <- make_split_fun(post = list(add_combo, rm_combo_from_placebo))

basic_table() %>%
  split_cols_by("ARM", split_fun = mysplit, show_colcounts = TRUE, colcount_format = "N=xx") %>%
  add_overall_col("Total") %>%
  append_topleft("Mean Age \\super a") %>%
  analyze("AGE") %>%
  build_table(df = adsl)

                    Placebo   Treatment A   Treatment B   Combined        
Mean Age \super a     N=2         N=2           N=2         N=4      Total
——————————————————————————————————————————————————————————————————————————
Mean                 27.50       25.00         32.00       28.50     28.17

The only way of displaying the N = xx is to pass the arguments to basic_table, which is not always desired. Can add_overall_col be updated to fix this?

basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>%
  split_cols_by("ARM", split_fun = mysplit) %>%
  add_overall_col("Total") %>%
  append_topleft("Mean Age \\super a") %>%
  analyze("AGE") %>%
  build_table(df = adsl)

                    Placebo   Treatment A   Treatment B   Combined   Total
Mean Age \super a     N=2         N=2           N=2         N=4       N=6 
——————————————————————————————————————————————————————————————————————————
Mean                 27.50       25.00         32.00       28.50     28.17

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions