Skip to contents

Teal Module: Summary of Variables

Usage

tm_t_summary(
  label,
  dataname,
  parentname = ifelse(inherits(arm_var, "data_extract_spec"),
    teal.transform::datanames_input(arm_var), "ADSL"),
  arm_var,
  summarize_vars,
  add_total = TRUE,
  useNA = c("ifany", "no"),
  na_level = "<Missing>",
  numeric_stats = c("n", "mean_sd", "mean_ci", "median", "median_ci", "quantiles",
    "range", "geom_mean"),
  denominator = c("N", "n", "omit"),
  drop_arm_levels = 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() or teal.transform::data_extract_spec())
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.

summarize_vars

(choices_selected or data_extract_spec)
names of the variables that should be summarized.

add_total

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

useNA

(character)
whether missing data (NA) should be displayed as a level.

na_level

(string)
used to replace all NA or empty values in character or factor variables in the data.

numeric_stats

(character)
selected statistics for numeric summarize variables to be displayed. Possible values are n, mean_sd, mean_ci, median, median_ci, quantiles, range and geom_mean. By default, n, mean_sd, median, range are selected.

denominator

(character)
chooses how percentages are calculated. With option N, the reference population from the column total is used as the denominator. With option n, the number of non-missing records in this row and column intersection is used as the denominator. If omit is chosen, then the percentage is omitted.

drop_arm_levels

(logical)
drop the unused arm_var levels. When TRUE, arm_var levels are set to those used in the dataname dataset. When FALSE, arm_var levels are set to those used in the parentname dataset. If dataname dataset and parentname dataset are the same (i.e. ADSL), then drop_arm_levels will always be TRUE regardless of the user choice when tm_t_summary is called.

pre_output

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

post_output

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

basic_table_args

optional, (basic_table_args)
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").

Examples

# Preparation of the test case.
library(dplyr)
library(scda)
library(tern)

adsl <- synthetic_cdisc_data("latest")$adsl

# Include `EOSDY` and `DCSREAS` variables below because they contain missing data.
stopifnot(
  any(is.na(adsl$EOSDY)),
  any(is.na(adsl$DCSREAS))
)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", adsl),
    code = 'ADSL <- synthetic_cdisc_data("latest")$adsl',
    check = TRUE
  ),
  modules = modules(
    tm_t_summary(
      label = "Demographic Table",
      dataname = "ADSL",
      arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
      add_total = TRUE,
      summarize_vars = choices_selected(
        c("SEX", "RACE", "BMRKR2", "EOSDY", "DCSREAS", "AGE"),
        c("SEX", "RACE")
      ),
      useNA = "ifany"
    )
  )
)
#> [INFO] 2022-10-14 09:11:22.2344 pid:3139 token:[] teal.modules.clinical Initializing tm_t_summary
if (FALSE) {
shinyApp(app$ui, app$server)
}