Skip to contents

This module produces an adverse events summary table.

Usage

tm_t_events_summary(
  label,
  dataname,
  parentname = ifelse(inherits(arm_var, "data_extract_spec"),
    teal.transform::datanames_input(arm_var), "ADSL"),
  arm_var,
  flag_var_anl = NULL,
  flag_var_aesi = NULL,
  dthfl_var =
    teal.transform::choices_selected(teal.transform::variable_choices(parentname,
    "DTHFL"), "DTHFL", fixed = TRUE),
  dcsreas_var =
    teal.transform::choices_selected(teal.transform::variable_choices(parentname,
    "DCSREAS"), "DCSREAS", fixed = TRUE),
  llt = teal.transform::choices_selected(teal.transform::variable_choices(dataname,
    "AEDECOD"), "AEDECOD", fixed = TRUE),
  aeseq_var = teal.transform::choices_selected(teal.transform::variable_choices(dataname,
    "AESEQ"), "AESEQ", fixed = TRUE),
  add_total = TRUE,
  total_label = default_total_label(),
  na_level = default_na_str(),
  count_subj = TRUE,
  count_pt = TRUE,
  count_events = TRUE,
  pre_output = NULL,
  post_output = NULL,
  basic_table_args = teal.widgets::basic_table_args()
)

Arguments

label

(character)
menu item label of the module in the teal app.

dataname

(character)
analysis data used in teal module.

parentname

(character)
parent analysis data used in teal module, usually this refers to ADSL.

arm_var

(teal.transform::choices_selected())
object with all available choices and preselected option for variable names that can be used as arm_var. It defines the grouping variable(s) in the results table. If there are two elements selected for arm_var, second variable will be nested under the first variable.

flag_var_anl

(teal.transform::choices_selected() or NULL)
vector with names of flag variables from dataset used to count adverse event sub-groups (e.g. Serious events, Related events, etc.). Variable labels are used as table row names if they exist.

flag_var_aesi

(teal.transform::choices_selected() or NULL)
vector with names of flag variables from dataset used to count adverse event special interest groups. All flag variables must be of type logical. Variable labels are used as table row names if they exist.

dthfl_var

(teal.transform::choices_selected())
object with all available choices and preselected option for variable names that can be used as death flag variable. Records with `"Y"`` are summarized in the table row for "Total number of deaths".

dcsreas_var

(teal.transform::choices_selected())
object with all available choices and preselected option for variable names that can be used as study discontinuation reason variable. Records with "ADVERSE EVENTS" are summarized in the table row for "Total number of patients withdrawn from study due to an AE".

llt

(teal.transform::choices_selected())
name of the variable with low level term for events.

aeseq_var

(teal.transform::choices_selected())
variable for adverse events sequence number from dataset. Used for counting total number of events.

add_total

(logical)
whether to include column with total number of patients.

total_label

(string)
string to display as total column/row label if column/row is enabled (see add_total). Defaults to "All Patients". To set a new default total_label to apply in all modules, run set_default_total_label("new_default").

na_level

(string)
used to replace all NA or empty values in character or factor variables in the data. Defaults to "<Missing>". To set a default na_level to apply in all modules, run set_default_na_str("new_default").

count_subj

(logical)
whether to show count of unique subjects (based on USUBJID). Only applies if event flag variables are provided.

count_pt

(logical)
whether to show count of unique preferred terms (based on llt). Only applies if event flag variables are provided.

count_events

(logical)
whether to show count of events (based on aeseq_var). Only applies if event flag variables are provided.

pre_output

(shiny.tag) optional,
with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional,
with text placed after the output to put the output into context. For example the shiny::helpText() elements are useful.

basic_table_args

(basic_table_args) optional
object created by teal.widgets::basic_table_args() with settings for the module table. The argument is merged with option teal.basic_table_args and with default module arguments (hard coded in the module body). For more details, see the vignette: vignette("custom-basic-table-arguments", package = "teal.widgets").

Value

a teal_module object.

See also

The TLG Catalog where additional example apps implementing this module can be found.

Examples

library(dplyr)

data <- teal_data()
data <- within(data, {
  ADSL <- tmc_ex_adsl %>%
    mutate(
      DTHFL = case_when(
        !is.na(DTHDT) ~ "Y",
        TRUE ~ ""
      ) %>% with_label("Subject Death Flag")
    )
  ADAE <- tmc_ex_adae

  add_event_flags <- function(dat) {
    dat <- dat %>%
      mutate(
        TMPFL_SER = AESER == "Y",
        TMPFL_REL = AEREL == "Y",
        TMPFL_GR5 = AETOXGR == "5",
        TMP_SMQ01 = !is.na(SMQ01NAM),
        TMP_SMQ02 = !is.na(SMQ02NAM),
        TMP_CQ01 = !is.na(CQ01NAM)
      )
    column_labels <- list(
      TMPFL_SER = "Serious AE",
      TMPFL_REL = "Related AE",
      TMPFL_GR5 = "Grade 5 AE",
      TMP_SMQ01 = aesi_label(dat[["SMQ01NAM"]], dat[["SMQ01SC"]]),
      TMP_SMQ02 = aesi_label("Y.9.9.9.9/Z.9.9.9.9 AESI"),
      TMP_CQ01 = aesi_label(dat[["CQ01NAM"]])
    )
    col_labels(dat)[names(column_labels)] <- as.character(column_labels)
    dat
  }

  #' Generating user-defined event flags.
  ADAE <- ADAE %>% add_event_flags()

  ae_anl_vars <- names(ADAE)[startsWith(names(ADAE), "TMPFL_")]
  aesi_vars <- names(ADAE)[startsWith(names(ADAE), "TMP_")]
})

datanames <- c("ADSL", "ADAE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]

app <- init(
  data = data,
  modules = modules(
    tm_t_events_summary(
      label = "Adverse Events Summary",
      dataname = "ADAE",
      arm_var = choices_selected(
        choices = variable_choices("ADSL", c("ARM", "ARMCD")),
        selected = "ARM"
      ),
      flag_var_anl = choices_selected(
        choices = variable_choices("ADAE", data[["ae_anl_vars"]]),
        selected = data[["ae_anl_vars"]][1],
        keep_order = TRUE,
        fixed = FALSE
      ),
      flag_var_aesi = choices_selected(
        choices = variable_choices("ADAE", data[["aesi_vars"]]),
        selected = data[["aesi_vars"]][1],
        keep_order = TRUE,
        fixed = FALSE
      ),
      add_total = TRUE
    )
  )
)
#> Initializing tm_t_events_summary
#> Warning: 'package:forcats' may not be available when loading
if (interactive()) {
  shinyApp(app$ui, app$server)
}