# Define the split functionsplit_fun <- drop_split_levelslyt <-basic_table() %>%summarize_patients_events_in_cols(filters_list = filters_list,empty_stats =c("all", "related", "fatal", "fatal_related"),custom_label ="Total number of patients with at least one serious adverse event" ) %>%split_rows_by("AEBODSYS",nested =FALSE,split_fun = split_fun,indent_mod =-1L,label_pos ="topleft",split_label =obj_label(adae_serious_arm$AEBODSYS) ) %>%split_rows_by("AEDECOD",split_fun = split_fun,label_pos ="topleft",split_label =obj_label(adae_serious_arm$AEDECOD) ) %>%summarize_patients_events_in_cols(filters_list = filters_list,col_split =FALSE )result <-build_table(lyt, adae_serious_arm)result
Body System or Organ Class
Dictionary-Derived Term Patients (All) Events (All) Events (Related) Events (Fatal) Events (Fatal & Related)
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one serious adverse event 104
cl A.1
dcd A.1.1.1.2 48 68 0 0 0
cl B.1
dcd B.1.1.1.1 47 56 56 56 56
cl B.2
dcd B.2.2.3.1 48 64 0 0 0
cl D.1
dcd D.1.1.1.1 50 61 61 61 61
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.
For illustrative purposes, the adae data is filtered by arm A: Drug X here.
Code
library(tern)library(dplyr)adae <- random.cdisc.data::cadae# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.adae <-df_explicit_na(adae)adae_serious <- adae %>%filter(AESER =="Y", SAFFL =="Y")adae_serious_arm <- adae_serious %>%filter(ARM =="A: Drug X")filters_list <-list(related =with_label(c(AEREL ="Y"), "Events (Related)"),fatal =with_label(c(AESDTH ="Y"), "Events (Fatal)"),fatal_related =with_label(c(AEREL ="Y", AESDTH ="Y"), "Events (Fatal & Related)"))