rtables icon indicating copy to clipboard operation
rtables copied to clipboard

Pagination loses indent mod on (at least) analyses when mutli-analysis is split across pages

Open gmbecker opened this issue 4 years ago • 0 comments

Discovered when responding to https://github.com/RConsortium/rtrs-wg/issues/32


adsl2 <- ex_adsl
adsl2$smoker <- factor(NA, levels = c("10 cigarettes", ">10 cigarettes"))
adsl2$age_grp <- cut(adsl2$AGE, c(18, 65, 75, 1000), labels = c("18 <= to < 65",
                                                                "65 <= to < 75",
                                                                "Elderly >= 75"))

## make one of the factor levels of SEX variable empty
adsl2 <- subset(adsl2, SEX != "UNDIFFERENTIATED")

## helper that omits the pct entirely if the count is 0
count_pct <- function(x, .N_col, ...) {
    if( x == 0 ) {
        rcell(0, format = "xx")
    } else {
        rcell(c(x, x/.N_col), format = "xx (xx.x%)")
    }
}

## analysis function: table factor then apply above to get our cell values
tab_w_pct <- function(x, .N_col, ...) {
    tab <- as.list(table(x))
    lapply(tab, count_pct, .N_col = .N_col)
}

lyt3 <- basic_table() %>%
    split_cols_by("ARM") %>%
    summarize_row_groups("USUBJID", label_fstr = "Number of Patients", format = "xx") %>%
    analyze("SEX", tab_w_pct, var_labels = "Gender", indent_mod = -1) %>%
    analyze("smoker", tab_w_pct, indent_mod = -1) %>%
    analyze("age_grp", tab_w_pct, indent_mod = -1)

tab <- build_table(lyt3, adsl2)

paginate_table(tab, lpp = 10)

Gives us

[[1]]
                     A: Drug X    B: Placebo   C: Combination
—————————————————————————————————————————————————————————————
Number of Patients      133          134            130      
Gender                                                       
  F                  79 (59.4%)   77 (57.5%)     66 (50.8%)  
  M                  51 (38.3%)   55 (41.0%)     60 (46.2%)  
  U                   3 (2.3%)     2 (1.5%)       4 (3.1%)   
  UNDIFFERENTIATED       0            0              0       

[[2]]
                      A: Drug X      B: Placebo    C: Combination
—————————————————————————————————————————————————————————————————
Number of Patients       133            134             130      
  smoker                                                         
    10 cigarettes         0              0               0       
    >10 cigarettes        0              0               0       
  age_grp                                                        
    18 <= to < 65    133 (100.0%)   134 (100.0%)    129 (99.2%)  
    65 <= to < 75         0              0            1 (0.8%)   
    Elderly >= 75         0              0               0       

Indentation on second page is wrong.

gmbecker avatar Jan 06 '22 20:01 gmbecker