# Define the split functionsplit_fun <- drop_split_levelslyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by(var ="ARM") %>%analyze_num_patients(vars ="USUBJID",.stats =c("unique", "nonunique"),.labels =c(unique ="Total number of patients with at least one treatment",nonunique ="Total number of treatments" ) ) %>%split_rows_by("CMCLAS",split_fun = split_fun,child_labels ="visible",nested =FALSE,indent_mod =1L,label_pos ="topleft",split_label =obj_label(adcm_con$CMCLAS) ) %>%summarize_num_patients(var ="USUBJID",.stats =c("unique", "nonunique"),.labels =c(unique ="Total number of patients with at least one treatment",nonunique ="Total number of treatments" ) ) %>%count_occurrences(vars ="CMDECOD", .indent_mods =-1L) %>%append_varlabels(adcm_con, "CMDECOD", indent =1L)result <-build_table(lyt = lyt,df = adcm_con,alt_counts_df = adsl) %>%prune_table() %>%sort_at_path(path =c("CMCLAS", "*", "CMDECOD"),scorefun = score_occurrences )result
Medication Class A: Drug X B: Placebo C: Combination
Standardized Medication Name (N=134) (N=134) (N=132)
—————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one treatment 117 (87.3%) 116 (86.6%) 116 (87.9%)
Total number of treatments 415 414 460
medcl A
Total number of patients with at least one treatment 75 (56.0%) 79 (59.0%) 81 (61.4%)
Total number of treatments 134 137 143
medname A_2/3 53 (39.6%) 50 (37.3%) 56 (42.4%)
medname A_3/3 45 (33.6%) 54 (40.3%) 48 (36.4%)
medcl B
Total number of patients with at least one treatment 83 (61.9%) 74 (55.2%) 88 (66.7%)
Total number of treatments 141 137 162
medname B_1/4 52 (38.8%) 57 (42.5%) 59 (44.7%)
medname B_4/4 50 (37.3%) 45 (33.6%) 55 (41.7%)
medcl C
Total number of patients with at least one treatment 82 (61.2%) 84 (62.7%) 89 (67.4%)
Total number of treatments 140 140 155
medname C_2/2 52 (38.8%) 58 (43.3%) 60 (45.5%)
medname C_1/2 51 (38.1%) 50 (37.3%) 56 (42.4%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by(var ="ARM") %>%analyze_num_patients(vars ="USUBJID",.stats =c("unique", "nonunique"),.labels =c(unique ="Total number of patients with at least one treatment",nonunique ="Total number of treatments" ) ) %>%split_rows_by("CMCLAS",split_fun = split_fun,child_labels ="visible",nested =FALSE,label_pos ="topleft",split_label =obj_label(adcm_con$CMCLAS) ) %>%summarize_num_patients(var ="USUBJID",.stats =c("unique", "nonunique"),.labels =c(unique ="Total number of patients with at least one treatment",nonunique ="Total number of treatments" ) ) %>%count_occurrences(vars ="CMDECOD", .indent_mods =-1L) %>%append_varlabels(adcm_prior, "CMDECOD", indent =1L)result <-build_table(lyt = lyt,df = adcm_prior,alt_counts_df = adsl) %>%prune_table() %>%sort_at_path(path =c("CMCLAS", "*", "CMDECOD"),scorefun = score_occurrences )result
Medication Class A: Drug X B: Placebo C: Combination
Standardized Medication Name (N=134) (N=134) (N=132)
—————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one treatment 89 (66.4%) 95 (70.9%) 106 (80.3%)
Total number of treatments 194 208 243
medcl A
Total number of patients with at least one treatment 54 (40.3%) 49 (36.6%) 69 (52.3%)
Total number of treatments 71 70 99
medname A_1/3 54 (40.3%) 49 (36.6%) 69 (52.3%)
medcl B
Total number of patients with at least one treatment 76 (56.7%) 80 (59.7%) 81 (61.4%)
Total number of treatments 123 138 144
medname B_2/4 52 (38.8%) 55 (41.0%) 56 (42.4%)
medname B_3/4 47 (35.1%) 47 (35.1%) 52 (39.4%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by(var ="ARM") %>%analyze_num_patients(vars ="USUBJID",.stats =c("unique", "nonunique"),.labels =c(unique ="Total number of patients with at least one treatment",nonunique ="Total number of treatments" ) ) %>%split_rows_by("CMCLAS",split_fun = split_fun, child_labels ="visible",nested =FALSE,label_pos ="topleft",split_label =obj_label(adcm_con$CMCLAS) ) %>%summarize_num_patients(var ="USUBJID",.labels =c(unique ="Total number of patients with at least one treatment"),.stats ="unique" ) %>%count_occurrences(vars ="CMDECOD", .indent_mods =-1L) %>%append_varlabels(adcm_con, "CMDECOD", indent =1L)result <-build_table(lyt = lyt,df = adcm_con,alt_counts_df = adsl) %>%prune_table() %>%sort_at_path(path =c("CMCLAS", "*", "CMDECOD"),scorefun = score_occurrences )result
Medication Class A: Drug X B: Placebo C: Combination
Standardized Medication Name (N=134) (N=134) (N=132)
———————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one treatment 117 (87.3%) 116 (86.6%) 116 (87.9%)
Total number of treatments 415 414 460
medcl A
Total number of patients with at least one treatment 75 (56.0%) 79 (59.0%) 81 (61.4%)
medname A_2/3 53 (39.6%) 50 (37.3%) 56 (42.4%)
medname A_3/3 45 (33.6%) 54 (40.3%) 48 (36.4%)
medcl B
Total number of patients with at least one treatment 83 (61.9%) 74 (55.2%) 88 (66.7%)
medname B_1/4 52 (38.8%) 57 (42.5%) 59 (44.7%)
medname B_4/4 50 (37.3%) 45 (33.6%) 55 (41.7%)
medcl C
Total number of patients with at least one treatment 82 (61.2%) 84 (62.7%) 89 (67.4%)
medname C_2/2 52 (38.8%) 58 (43.3%) 60 (45.5%)
medname C_1/2 51 (38.1%) 50 (37.3%) 56 (42.4%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by(var ="ARM") %>%add_overall_col("All Patients") %>%analyze_num_patients(vars ="USUBJID",.stats =c("unique", "nonunique"),.labels =c("Total number of patients with at least one treatment (%)","Total number of treatments" ) ) %>%split_rows_by("CMCLAS",split_fun = split_fun,child_labels ="visible",nested =FALSE,label_pos ="topleft",split_label =obj_label(adcm_con$CMCLAS) ) %>%summarize_num_patients(var ="USUBJID",.stats =c("unique", "nonunique"),.labels =c("Total number of patients with at least one treatment (%)","Total number of treatments" ) ) %>%count_occurrences(vars ="CMDECOD", .indent_mods =-1L) %>%append_varlabels(adcm_con, "CMDECOD", indent =1L)result <-build_table(lyt = lyt,df = adcm_con,alt_counts_df = adsl) %>%prune_table() %>%sort_at_path(path =c("CMCLAS", "*", "CMDECOD"),scorefun = score_occurrences,decreasing =TRUE ) %>%sort_at_path(path =c("CMCLAS"),scorefun = cont_n_allcols,decreasing =TRUE )result
Medication Class A: Drug X B: Placebo C: Combination All Patients
Standardized Medication Name (N=134) (N=134) (N=132) (N=400)
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one treatment (%) 117 (87.3%) 116 (86.6%) 116 (87.9%) 349 (87.2%)
Total number of treatments 415 414 460 1289
medcl C
Total number of patients with at least one treatment (%) 82 (61.2%) 84 (62.7%) 89 (67.4%) 255 (63.7%)
Total number of treatments 140 140 155 435
medname C_2/2 52 (38.8%) 58 (43.3%) 60 (45.5%) 170 (42.5%)
medname C_1/2 51 (38.1%) 50 (37.3%) 56 (42.4%) 157 (39.2%)
medcl B
Total number of patients with at least one treatment (%) 83 (61.9%) 74 (55.2%) 88 (66.7%) 245 (61.3%)
Total number of treatments 141 137 162 440
medname B_1/4 52 (38.8%) 57 (42.5%) 59 (44.7%) 168 (42.0%)
medname B_4/4 50 (37.3%) 45 (33.6%) 55 (41.7%) 150 (37.5%)
medcl A
Total number of patients with at least one treatment (%) 75 (56.0%) 79 (59.0%) 81 (61.4%) 235 (58.8%)
Total number of treatments 134 137 143 414
medname A_2/3 53 (39.6%) 50 (37.3%) 56 (42.4%) 159 (39.8%)
medname A_3/3 45 (33.6%) 54 (40.3%) 48 (36.4%) 147 (36.8%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
Code
library(dplyr)library(tern)# The following tables require ADCM data structure that follows the legacy concomitant medication coding.# WHO coding is not used.adsl <- random.cdisc.data::cadsladcm <- random.cdisc.data::cadcm# Below step is to set up example data based on legacy standard.adcm <- adcm %>%select(-starts_with("ATC")) %>%unique()# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.adsl <-df_explicit_na(adsl)adcm <-df_explicit_na(adcm)adcm_con <- adcm %>%filter(ATIREL =="CONCOMITANT")adcm_prior <- adcm %>%filter(ATIREL =="PRIOR")
Here, adcm is processed to keep only one path per treatment.
Code
library(teal.modules.clinical)## Data reproducible codedata <-teal_data()data <-within(data, {library(dplyr) ADSL <- random.cdisc.data::cadsl ADCM <- random.cdisc.data::cadcm# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. ADSL <-df_explicit_na(ADSL) ADCM <-df_explicit_na(ADCM) ADCM <- ADCM %>%group_by(STUDYID, USUBJID, CMDECOD) %>%slice(1) %>%ungroup()})datanames <-c("ADSL", "ADCM")datanames(data) <- datanamesjoin_keys(data) <- default_cdisc_join_keys[datanames]## Reusable Configuration For ModulesADCM <- data[["ADCM"]]## Setup Appapp <-init(data = data,modules =modules(tm_t_events(label ="Concomitant Medication Table",dataname ="ADCM",arm_var =choices_selected(c("ARM", "ARMCD"), "ARM"),llt =choices_selected(choices =variable_choices(ADCM, "CMDECOD"),selected ="CMDECOD" ),hlt =choices_selected(choices =variable_choices(ADCM, "CMCLAS"),selected =c("CMCLAS") ),add_total =TRUE,event_type ="treatment" ) ))shinyApp(app$ui, app$server)
Experimental use!
shinylive allow you to modify to run shiny application entirely in the web browser. Modify the code below and click re-run the app to see the results. The performance is slighly worse and some of the features (e.g. downloading) might not work at all.
#| '!! shinylive warning !!': |#| shinylive does not work in self-contained HTML documents.#| Please set `embed-resources: false` in your metadata.#| standalone: true#| viewerHeight: 800#| editorHeight: 200#| components: [viewer, editor]#| layout: vertical# -- WEBR HELPERS --options(webr_pkg_repos = c("r-universe" = "https://insightsengineering.r-universe.dev", getOption("webr_pkg_repos")))# -- APP CODE --library(teal.modules.clinical)## Data reproducible codedata <- teal_data()data <- within(data, { library(dplyr) ADSL <- random.cdisc.data::cadsl ADCM <- random.cdisc.data::cadcm # Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. ADSL <- df_explicit_na(ADSL) ADCM <- df_explicit_na(ADCM) ADCM <- ADCM %>% group_by(STUDYID, USUBJID, CMDECOD) %>% slice(1) %>% ungroup()})datanames <- c("ADSL", "ADCM")datanames(data) <- datanamesjoin_keys(data) <- default_cdisc_join_keys[datanames]## Reusable Configuration For ModulesADCM <- data[["ADCM"]]## Setup Appapp <- init( data = data, modules = modules( tm_t_events( label = "Concomitant Medication Table", dataname = "ADCM", arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"), llt = choices_selected( choices = variable_choices(ADCM, "CMDECOD"), selected = "CMDECOD" ), hlt = choices_selected( choices = variable_choices(ADCM, "CMCLAS"), selected = c("CMCLAS") ), add_total = TRUE, event_type = "treatment" ) ))shinyApp(app$ui, app$server)