# 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)"))
---title: EUDRAT02subtitle: Serious Adverse Events, Fatal Serious Adverse Events, and Serious Adverse Events Related to Study Medication---------------------------------------------------------------------------{{< include ../../_utils/envir_hook.qmd >}}```{r setup, echo = FALSE, warning = FALSE, message = FALSE}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)"))``````{r include = FALSE}webr_code_labels <-c("setup")```{{< include ../../_utils/webr_no_include.qmd >}}## Output:::: panel-tabset## Standard Table::: {.panel-tabset .nav-justified group="webr"}## {{< fa regular file-lines sm fw >}} Preview```{r variant1, test = list(result_v1 = "result")}# 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``````{r include = FALSE}webr_code_labels <-c("variant1")```{{< include ../../_utils/webr.qmd >}}:::## Data SetupFor illustrative purposes, the `adae` data is filtered by arm `A: Drug X` here.```{r setup}#| code-fold: show```::::{{< include ../../_utils/save_results.qmd >}}{{< include ../../repro.qmd >}}