insightsengineering / tern

Table, Listings, and Graphs (TLG) library for common outputs used in clinical trials
https://insightsengineering.github.io/tern/
Other
77 stars 21 forks source link

split_cols_by only allows variables from alt_counts_df argument #535

Open yli110-stat697 opened 2 years ago

yli110-stat697 commented 2 years ago

For my recent Ophthalmology studies, we got table requests like blow

Screen Shot 2022-04-29 at 6 07 15 PM Screen Shot 2022-04-29 at 6 08 05 PM

For these tables, the nested columns are from variables in analysis dataset instead of the alt_counts_df dataset. For sample codes

adsl <- synthetic_cdisc_data("latest")$adsl
adcm <- synthetic_cdisc_data("latest")$adcm
adcm$STATUS <- c(rep("ongoing", 2000), rep("resolved", 1685))
basic_table() %>%
  split_cols_by("ARMCD") %>%
  add_colcounts() %>%
  split_cols_by("STATUS") %>%
  summarize_num_patients("USUBJID") %>%
  build_table(adcm, alt_counts_df = adsl)

will give the error message

Error in FUN(X[[i]], ...) : 
  alt_counts_df (or df) appears incompatible with column-split structure. Offending column subset expression: ((!is.na(ARMCD) & ARMCD %in% "ARM A")) & (!is.na(STATUS) & STATUS %in% 
Original error message: object 'STATUS' not foundalt_counts_df (or df) appears incompatible with column-split structure. Offending column subset expression:     "ongoing")
Original error message: object 'STATUS' not found

If we do

basic_table() %>%
    split_cols_by("ARMCD") %>%
    add_colcounts() %>%
    split_cols_by("STATUS") %>%
    summarize_num_patients("USUBJID") %>%
    build_table(adcm)

how can we get the patients count in the column header?

yli110-stat697 commented 2 years ago

Hi @shajoezhu and @yangx61 , this is new feature requested for tern, but potentially need rtables update I assume?