Skip to content

Bug: summarize_row_groups() does not provide the correct .ref_group #1117

Description

@wwojciech

It seems that .ref_group is not correctly populated when using summarize_row_groups() with a custom tabulation function.

In the example below, analyze() correctly provides the reference group data, while summarize_row_groups() passes a zero-row .ref_group.

Example

nrow_refgrp <- function(df, labelstr = "", .ref_group) {
  rcell(nrow(.ref_group), label = "nrow(.ref_group)")
}

lyt0 <- basic_table(show_colcounts = TRUE, top_level_section_div = " ") |>
  split_cols_by("ARM", ref_group = "B: Placebo") |>
  split_rows_by("SEX", split_fun = drop_split_levels, child_labels = "visible")

analyze()

lyt0 |>
  analyze("AGE", afun = nrow_refgrp) |>
  build_table(DM)
                     A: Drug X   B: Placebo   C: Combination
                      (N=121)     (N=106)        (N=129)    
————————————————————————————————————————————————————————————
F                                                           
  nrow(.ref_group)      56           56             56      
M                                                           
  nrow(.ref_group)      50           50             50

summarize_row_groups()

lyt0 |>
  summarize_row_groups("SEX", format = NULL, cfun = nrow_refgrp) |>
  build_table(DM)
                     A: Drug X   B: Placebo   C: Combination
                      (N=121)     (N=106)        (N=129)    
————————————————————————————————————————————————————————————
F                                                           
  nrow(.ref_group)       0           0              0       
M                                                           
  nrow(.ref_group)       0           0              0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions