tern icon indicating copy to clipboard operation
tern copied to clipboard

split_cols_by only allows variables from alt_counts_df argument

Open yli110-stat697 opened this issue 3 years ago • 1 comments

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 avatar Apr 29 '22 19:04 yli110-stat697

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

yli110-stat697 avatar Apr 29 '22 19:04 yli110-stat697