diff --git a/DESCRIPTION b/DESCRIPTION index 72101c7c..71c90eb1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,8 +14,8 @@ Depends: R (>= 3.6), tern (>= 0.9.5) Imports: - cards (>= 0.2.0), - cardx (>= 0.2.0), + cards (>= 0.3.0), + cardx (>= 0.2.1), checkmate (>= 2.1.0), cowplot (>= 1.0.0), dplyr (>= 1.0.0), diff --git a/NAMESPACE b/NAMESPACE index 53e3fc77..dfff5c37 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,7 +22,11 @@ export(make_table_09_gtsum) export(make_table_09_tplyr) export(make_table_10) export(make_table_11) +export(make_table_11_gtsummary) +export(make_table_11_rtables) export(make_table_12) +export(make_table_12_gtsummary) +export(make_table_12_rtables) export(make_table_13) export(make_table_14) export(make_table_15) diff --git a/R/fda-table_11.R b/R/fda-table_11.R index 333ab094..e80e11e4 100644 --- a/R/fda-table_11.R +++ b/R/fda-table_11.R @@ -2,22 +2,24 @@ #' Discontinuation, Safety Population, Pooled Analyses #' #' @details -#' * `adae` must contain the variables `AEBODSYS`, `DCSREAS`, and the variables specified by +#' * `df` must contain the variables `AEBODSYS`, `DCSREAS`, and the variables specified by #' `arm_var`, `id_var`, `saffl_var`, `fmqsc_var`, and `fmqnam_var`. -#' * If specified, `alt_counts_df` must contain `USUBJID` and the variables specified by `arm_var` and `saffl_var`. +#' * If specified, `denominator` must contain `USUBJID` and the variables specified by `arm_var` and `saffl_var`. #' * A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at #' least one record with `DCSREAS = "ADVERSE EVENT"`. #' * `fmqsc_var` must contain "BROAD" or "NARROW" values, one of which will be displayed in the table. Narrow is #' selected by default (see `fmq_scope` argument). #' * Flag variables (i.e. `XXXFL`) are expected to have two levels: `"Y"` (true) and `"N"` (false). Missing values in #' flag variables are treated as `"N"`. -#' * Columns are split by arm. Overall population column is excluded by default (see `lbl_overall` argument). #' * Numbers in table represent the absolute numbers of patients and fraction of `N`. -#' * All-zero rows are removed by default (see `prune_0` argument). #' +#' @inheritParams tbl_make_table_11 #' @inheritParams argument_convention #' -#' @return An `rtable` object. +#' @return A `gtsummary` table and, if `return_ard = TRUE`, an ARD. +#' If `return_ard = TRUE`, they will be returned as a list with named elements `table` and `ard`. +#' +#' @seealso [`tbl_make_table_11`] #' #' @examples #' library(dplyr) @@ -35,40 +37,231 @@ #' adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" #' adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" #' -#' tbl <- make_table_11(adae = adae, alt_counts_df = adsl) +#' tbl <- make_table_11(df = adae, denominator = adsl) #' tbl #' #' @export -make_table_11 <- function(adae, - alt_counts_df = NULL, - show_colcounts = TRUE, +make_table_11 <- function(df, + denominator = NULL, + return_ard = TRUE, id_var = "USUBJID", arm_var = "ARM", saffl_var = "SAFFL", fmqsc_var = "FMQ01SC", fmqnam_var = "FMQ01NAM", fmq_scope = "NARROW", - lbl_overall = NULL, - risk_diff = NULL, - prune_0 = TRUE, - na_level = "", - annotations = NULL) { + na_level = "") { + ard <- ard_table_11( + df = df, + denominator = denominator, + id_var = id_var, + arm_var = arm_var, + saffl_var = saffl_var, + fmqsc_var = fmqsc_var, + fmqnam_var = fmqnam_var, + fmq_scope = fmq_scope, + na_level = na_level + ) + + tbl <- make_table_11_gtsummary( + df = df, + denominator = denominator, + id_var = id_var, + arm_var = arm_var, + saffl_var = saffl_var, + fmqsc_var = fmqsc_var, + fmqnam_var = fmqnam_var, + fmq_scope = fmq_scope, + na_level = na_level + ) + + if (return_ard) { + return(list(table = tbl, ard = ard)) + } else { + return(tbl) # nocov + } +} + +#' Pre-Process Data for Table 11 Creation +#' +#' @keywords internal +preproc_df_table_11 <- function(df, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + na_level = "") { assert_subset(c( "AEBODSYS", "DCSREAS", arm_var, id_var, saffl_var, fmqsc_var, fmqnam_var - ), names(adae)) - assert_flag_variables(adae, saffl_var) + ), names(df)) + assert_flag_variables(df, saffl_var) assert_subset(toupper(fmq_scope), c("NARROW", "BROAD")) - id_dcsae <- adae %>% + id_dcsae <- df %>% filter(DCSREAS == "ADVERSE EVENT") %>% select(all_of(c(id_var))) %>% unlist() - adae <- adae %>% + df <- df %>% filter(.data[[saffl_var]] == "Y", .data[[id_var]] %in% id_dcsae, .data[[fmqsc_var]] == fmq_scope) %>% df_explicit_na(na_level = na_level) - adae[[fmqnam_var]] <- with_label(adae[[fmqnam_var]], paste0("FMQ (", tools::toTitleCase(tolower(fmq_scope)), ")")) + df[[fmqnam_var]] <- with_label(df[[fmqnam_var]], paste0("FMQ (", tools::toTitleCase(tolower(fmq_scope)), ")")) + + df +} +#' Make ARD: Table 11 +#' +#' @examples +#' library(dplyr) +#' +#' adsl <- random.cdisc.data::cadsl +#' adae <- random.cdisc.data::cadae +#' +#' set.seed(1) +#' adae <- adae %>% +#' rename(FMQ01SC = SMQ01SC) %>% +#' mutate( +#' AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), +#' FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) +#' ) +#' adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +#' adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" +#' +#' ard <- cardinal:::ard_table_11(adae, adsl) +#' ard +#' +#' @keywords internal +#' @name ard_make_table_11 +ard_table_11 <- function(df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + na_level = "") { + df <- preproc_df_table_11(df, id_var, arm_var, saffl_var, fmqsc_var, fmqnam_var, fmq_scope, na_level) + + if (is.null(denominator)) { + denominator <- df # nocov + } else { + denominator <- alt_counts_df_preproc(denominator, id_var, arm_var, saffl_var) + } + + ard <- ard_hierarchical( + data = df, + variables = all_of(c("AEBODSYS", fmqnam_var)), + by = all_of(arm_var), + denominator = denominator, + id = all_of(id_var) + ) + + ard +} + +#' Engine-Specific Functions: Table 11 +#' +#' The table engine used by each engine-specific function is identified by its suffix. +#' +#' @inheritParams argument_convention +#' +#' @details +#' * `df` must contain the variables `AEBODSYS`, `DCSREAS`, and the variables specified by +#' `arm_var`, `id_var`, `saffl_var`, `fmqsc_var`, and `fmqnam_var`. +#' * If specified, `denominator` (or `alt_counts_df`) must contain `USUBJID` and the variables specified by `arm_var` +#' and `saffl_var`. +#' * A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at +#' least one record with `DCSREAS = "ADVERSE EVENT"`. +#' * `fmqsc_var` must contain "BROAD" or "NARROW" values, one of which will be displayed in the table. Narrow is +#' selected by default (see `fmq_scope` argument). +#' * Flag variables (i.e. `XXXFL`) are expected to have two levels: `"Y"` (true) and `"N"` (false). Missing values in +#' flag variables are treated as `"N"`. +#' * Numbers in table represent the absolute numbers of patients and fraction of `N`. +#' * All-zero rows are removed by default by `make_table_11_rtables()` (see `prune_0` argument). +#' +#' @return +#' * `make_table_11_gtsummary()` returns a `gtsummary` object. +#' * `make_table_11_rtables()` returns an `rtable` object. +#' +#' @seealso [make_table_11()] +#' +#' @examples +#' library(dplyr) +#' +#' adsl <- random.cdisc.data::cadsl +#' adae <- random.cdisc.data::cadae +#' +#' set.seed(1) +#' adae <- adae %>% +#' rename(FMQ01SC = SMQ01SC) %>% +#' mutate( +#' AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), +#' FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) +#' ) +#' adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +#' adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" +#' +#' # gtsummary table -------------- +#' tbl_gtsummary <- cardinal:::make_table_11_gtsummary(df = adae, denominator = adsl) +#' tbl_gtsummary +#' +#' # rtables table ---------------- +#' tbl_rtables <- cardinal:::make_table_11_rtables(df = adae, alt_counts_df = adsl) +#' tbl_rtables +#' +#' @export +#' @name tbl_make_table_11 +make_table_11_gtsummary <- function(df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + na_level = "") { + df <- preproc_df_table_11(df, id_var, arm_var, saffl_var, fmqsc_var, fmqnam_var, fmq_scope, na_level) + + if (is.null(denominator)) { + denominator <- df # nocov + } else { + denominator <- alt_counts_df_preproc(denominator, id_var, arm_var, saffl_var) + } + + tbl <- tbl_hierarchical( + df, + variables = all_of(c("AEBODSYS", fmqnam_var)), + by = all_of(arm_var), + id = all_of(id_var), + denominator = denominator, + overall_row = TRUE, + label = list(overall = "Patients with at least one AE leading to discontinuation") + ) + + tbl +} + +#' @export +#' @rdname tbl_make_table_11 +make_table_11_rtables <- function(df, + alt_counts_df = NULL, + show_colcounts = TRUE, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + lbl_overall = NULL, + risk_diff = NULL, + prune_0 = TRUE, + na_level = "", + annotations = NULL) { + df <- preproc_df_table_11(df, id_var, arm_var, saffl_var, fmqsc_var, fmqnam_var, fmq_scope, na_level) alt_counts_df <- alt_counts_df_preproc(alt_counts_df, id_var, arm_var, saffl_var) lyt <- basic_table_annot(show_colcounts, annotations) %>% @@ -82,7 +275,7 @@ make_table_11 <- function(adae, split_rows_by( "AEBODSYS", label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) + split_label = obj_label(df$AEBODSYS) ) %>% summarize_num_patients( var = id_var, @@ -95,9 +288,9 @@ make_table_11 <- function(adae, drop = FALSE, riskdiff = !is.null(risk_diff) ) %>% - append_varlabels(adae, fmqnam_var, indent = 1L) + append_varlabels(df, fmqnam_var, indent = 1L) - tbl <- build_table(lyt, df = adae, alt_counts_df = alt_counts_df) + tbl <- build_table(lyt, df = df, alt_counts_df = alt_counts_df) if (prune_0) tbl <- prune_table(tbl) tbl diff --git a/R/fda-table_12.R b/R/fda-table_12.R index a41810d6..def26340 100644 --- a/R/fda-table_12.R +++ b/R/fda-table_12.R @@ -2,55 +2,216 @@ #' by System Organ Class and Preferred Term, Safety Population, Pooled Analyses #' #' @details -#' * `adae` must contain `DCSREAS`, `AESOC`, and the variables specified by `arm_var`, `id_var`, `saffl_var`, +#' * `df` must contain `DCSREAS`, `AESOC`, and the variables specified by `arm_var`, `id_var`, `saffl_var`, #' and `pref_var`. -#' * If specified, `alt_counts_df` must contain `USUBJID` and the variables specified by `arm_var` and `saffl_var`. +#' * If specified, `denominator` must contain `USUBJID` and the variables specified by `arm_var` and `saffl_var`. #' * A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at #' least one record with `DCSREAS = "ADVERSE EVENT"`. #' * Flag variables (i.e. `XXXFL`) are expected to have two levels: `"Y"` (true) and `"N"` (false). Missing values in #' flag variables are treated as `"N"`. -#' * Columns are split by arm. Overall population column is excluded by default (see `lbl_overall` argument). #' * Numbers in table represent the absolute numbers of patients and fraction of `N`. -#' * All-zero rows are removed by default (see `prune_0` argument). #' +#' @inheritParams tbl_make_table_12 #' @inheritParams argument_convention #' -#' @return An `rtable` object. +#' @return A `gtsummary` table and, if `return_ard = TRUE`, an ARD. +#' If `return_ard = TRUE`, they will be returned as a list with named elements `table` and `ard`. +#' +#' @seealso [`tbl_make_table_12`] #' #' @examples #' adsl <- random.cdisc.data::cadsl #' adae <- random.cdisc.data::cadae #' adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" #' -#' tbl <- make_table_12(adae = adae, alt_counts_df = adsl) +#' tbl <- make_table_12(df = adae, denominator = adsl) #' tbl #' #' @export -make_table_12 <- function(adae, - alt_counts_df = NULL, - show_colcounts = TRUE, +make_table_12 <- function(df, + denominator = NULL, + return_ard = TRUE, id_var = "USUBJID", arm_var = "ARM", saffl_var = "SAFFL", - pref_var = "AEDECOD", - lbl_overall = NULL, - risk_diff = NULL, - prune_0 = TRUE, - annotations = NULL) { + pref_var = "AEDECOD") { + ard <- ard_table_12( + df = df, + denominator = denominator, + id_var = id_var, + arm_var = arm_var, + saffl_var = saffl_var, + pref_var = pref_var + ) + + tbl <- make_table_12_gtsummary( + df = df, + denominator = denominator, + id_var = id_var, + arm_var = arm_var, + saffl_var = saffl_var, + pref_var = pref_var + ) + + if (return_ard) { + return(list(table = tbl, ard = ard)) + } else { + return(tbl) # nocov + } +} + +#' Pre-Process Data for Table 12 Creation +#' +#' @keywords internal +preproc_df_table_12 <- function(df, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD") { assert_subset(c( "AEBODSYS", "DCSREAS", arm_var, id_var, saffl_var, pref_var - ), names(adae)) - assert_flag_variables(adae, saffl_var) + ), names(df)) + assert_flag_variables(df, saffl_var) - id_dcsae <- adae %>% + id_dcsae <- df %>% filter(DCSREAS == "ADVERSE EVENT") %>% select(all_of(c(id_var))) %>% unlist() - adae <- adae %>% + df <- df %>% filter(.data[[saffl_var]] == "Y", .data[[id_var]] %in% id_dcsae) %>% df_explicit_na() + df +} + +#' Make ARD: Table 12 +#' +#' @examples +#' library(dplyr) +#' +#' adsl <- random.cdisc.data::cadsl +#' adae <- random.cdisc.data::cadae +#' +#' set.seed(1) +#' adae <- adae %>% +#' rename(FMQ01SC = SMQ01SC) %>% +#' mutate( +#' AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), +#' FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) +#' ) +#' adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +#' adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" +#' +#' ard <- cardinal:::ard_table_12(adae, adsl) +#' ard +#' +#' @keywords internal +#' @name ard_make_table_12 +ard_table_12 <- function(df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD") { + df <- preproc_df_table_12(df, id_var, arm_var, saffl_var, pref_var) + + if (is.null(denominator)) { + denominator <- df # nocov + } else { + denominator <- alt_counts_df_preproc(denominator, id_var, arm_var, saffl_var) + } + + ard <- ard_hierarchical( + data = df, + variables = all_of(c("AEBODSYS", pref_var)), + by = all_of(arm_var), + denominator = denominator, + id = all_of(id_var) + ) + + ard +} + +#' Engine-Specific Functions: Table 12 +#' +#' The table engine used by each engine-specific function is identified by its suffix. +#' +#' @inheritParams argument_convention +#' +#' @details +#' * `df` must contain `DCSREAS`, `AESOC`, and the variables specified by `arm_var`, `id_var`, `saffl_var`, +#' and `pref_var`. +#' * If specified, `denominator` must contain `USUBJID` and the variables specified by `arm_var` and `saffl_var`. +#' * A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at +#' least one record with `DCSREAS = "ADVERSE EVENT"`. +#' * Flag variables (i.e. `XXXFL`) are expected to have two levels: `"Y"` (true) and `"N"` (false). Missing values in +#' flag variables are treated as `"N"`. +#' * Numbers in table represent the absolute numbers of patients and fraction of `N`. +#' * All-zero rows are removed by default by `make_table_12_rtables()` (see `prune_0` argument). +#' +#' @return +#' * `make_table_12_gtsummary()` returns a `gtsummary` object. +#' * `make_table_12_rtables()` returns an `rtable` object. +#' +#' @seealso [make_table_12()] +#' +#' @examples +#' adsl <- random.cdisc.data::cadsl +#' adae <- random.cdisc.data::cadae +#' adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +#' +#' # gtsummary table -------------- +#' tbl_gtsummary <- cardinal:::make_table_12_gtsummary(df = adae, denominator = adsl) +#' tbl_gtsummary +#' +#' # rtables table ---------------- +#' tbl_rtables <- cardinal:::make_table_12_rtables(df = adae, alt_counts_df = adsl) +#' tbl_rtables +#' +#' @export +#' @name tbl_make_table_12 +make_table_12_gtsummary <- function(df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD") { + df <- preproc_df_table_12(df, id_var, arm_var, saffl_var, pref_var) + + if (is.null(denominator)) { + denominator <- df # nocov + } else { + denominator <- alt_counts_df_preproc(denominator, id_var, arm_var, saffl_var) + } + + tbl <- tbl_hierarchical( + df, + variables = all_of(c("AEBODSYS", pref_var)), + by = all_of(arm_var), + id = all_of(id_var), + denominator = denominator, + overall_row = TRUE, + label = list(overall = "Patients with at least one AE leading to discontinuation") + ) + + tbl +} + +#' @export +#' @rdname tbl_make_table_12 +make_table_12_rtables <- function(df, + alt_counts_df = NULL, + show_colcounts = TRUE, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD", + lbl_overall = NULL, + risk_diff = NULL, + prune_0 = TRUE, + annotations = NULL) { + df <- preproc_df_table_12(df, id_var, arm_var, saffl_var, pref_var) alt_counts_df <- alt_counts_df_preproc(alt_counts_df, id_var, arm_var, saffl_var) lyt <- basic_table_annot(show_colcounts, annotations) %>% @@ -64,7 +225,7 @@ make_table_12 <- function(adae, split_rows_by( "AEBODSYS", label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) + split_label = obj_label(df$AEBODSYS) ) %>% summarize_num_patients( var = id_var, @@ -77,9 +238,9 @@ make_table_12 <- function(adae, drop = FALSE, riskdiff = !is.null(risk_diff) ) %>% - append_varlabels(adae, pref_var, indent = 1L) + append_varlabels(df, pref_var, indent = 1L) - tbl <- build_table(lyt, df = adae, alt_counts_df = alt_counts_df) + tbl <- build_table(lyt, df = df, alt_counts_df = alt_counts_df) if (prune_0) tbl <- prune_table(tbl) tbl diff --git a/man/ard_make_table_11.Rd b/man/ard_make_table_11.Rd new file mode 100644 index 00000000..53499062 --- /dev/null +++ b/man/ard_make_table_11.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fda-table_11.R +\name{ard_make_table_11} +\alias{ard_make_table_11} +\alias{ard_table_11} +\title{Make ARD: Table 11} +\usage{ +ard_table_11( + df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + na_level = "" +) +} +\description{ +Make ARD: Table 11 +} +\examples{ +library(dplyr) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae + +set.seed(1) +adae <- adae \%>\% + rename(FMQ01SC = SMQ01SC) \%>\% + mutate( + AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), + FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) + ) +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" + +ard <- cardinal:::ard_table_11(adae, adsl) +ard + +} +\keyword{internal} diff --git a/man/ard_make_table_12.Rd b/man/ard_make_table_12.Rd new file mode 100644 index 00000000..2ea59f4d --- /dev/null +++ b/man/ard_make_table_12.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fda-table_12.R +\name{ard_make_table_12} +\alias{ard_make_table_12} +\alias{ard_table_12} +\title{Make ARD: Table 12} +\usage{ +ard_table_12( + df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD" +) +} +\description{ +Make ARD: Table 12 +} +\examples{ +library(dplyr) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae + +set.seed(1) +adae <- adae \%>\% + rename(FMQ01SC = SMQ01SC) \%>\% + mutate( + AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), + FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) + ) +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" + +ard <- cardinal:::ard_table_12(adae, adsl) +ard + +} +\keyword{internal} diff --git a/man/make_table_11.Rd b/man/make_table_11.Rd index 44c2b98a..87faa7a1 100644 --- a/man/make_table_11.Rd +++ b/man/make_table_11.Rd @@ -6,28 +6,24 @@ Discontinuation, Safety Population, Pooled Analyses} \usage{ make_table_11( - adae, - alt_counts_df = NULL, - show_colcounts = TRUE, + df, + denominator = NULL, + return_ard = TRUE, id_var = "USUBJID", arm_var = "ARM", saffl_var = "SAFFL", fmqsc_var = "FMQ01SC", fmqnam_var = "FMQ01NAM", fmq_scope = "NARROW", - lbl_overall = NULL, - risk_diff = NULL, - prune_0 = TRUE, - na_level = "", - annotations = NULL + na_level = "" ) } \arguments{ -\item{adae}{(\code{data.frame})\cr dataset (typically ADAE) required to build table.} +\item{df}{(\code{data.frame})\cr dataset required to build table.} -\item{alt_counts_df}{(\code{character})\cr alternative dataset (typically ADSL) used only to calculate column counts.} +\item{denominator}{(\code{data.frame})\cr alternative dataset (typically ADSL) used only to calculate denominator counts.} -\item{show_colcounts}{(\code{flag})\cr Whether column counts should be printed. Boolean.} +\item{return_ard}{(\code{flag})\cr whether an ARD should be returned. Defaults to \code{TRUE}.} \item{id_var}{(\code{character})\cr variable used as unique subject identifier.} @@ -41,32 +37,11 @@ make_table_11( \item{fmq_scope}{(\code{character})\cr FMQ scope ("NARROW" or "BROAD") to output in table.} -\item{lbl_overall}{(\code{character})\cr if specified, an overall column will be added to the table with -the given value as the column label.} - -\item{risk_diff}{(named \code{list})\cr list of settings to apply to add one or more risk difference columns to the table. -Defaults to \code{NULL} (no risk difference column added). See \code{\link[tern:add_riskdiff]{tern::add_riskdiff()}} for more details. List should -contain the following elements: -\itemize{ -\item \code{arm_x}: (required) the name of reference arm. -\item \code{arm_y}: (required) the names of the arms to compare to the reference arm. A new column will be added for each -element of \code{arm_y}. -\item \code{col_label}: (optional) labels to use for the risk difference columns. Defaults to -\code{"Risk Difference (\%) (95\% CI)"}. For more than one risk difference column, \code{"arm x vs. arm y"} text will also -be included in the column labels by default. The length of \code{col_label} must be equal to the length of \code{arm_y}. -\item \code{pct}: (optional) whether the output should be returned as percentages. Defaults to \code{TRUE}. -}} - -\item{prune_0}{(\code{flag})\cr Whether all-zero rows should be removed from the table. Boolean.} - \item{na_level}{(\code{character})\cr string to represent missing values.} - -\item{annotations}{(named \code{list} of \code{character})\cr list of annotations to add to the table. Valid -annotation types are \code{title}, \code{subtitles}, \code{main_footer}, and \code{prov_footer}. Each name-value pair should -use the annotation type as name and the desired string as value.} } \value{ -An \code{rtable} object. +A \code{gtsummary} table and, if \code{return_ard = TRUE}, an ARD. +If \code{return_ard = TRUE}, they will be returned as a list with named elements \code{table} and \code{ard}. } \description{ FDA Table 11: Patients with FDA Medical Query (Narrow) Leading to Treatment @@ -74,18 +49,16 @@ Discontinuation, Safety Population, Pooled Analyses } \details{ \itemize{ -\item \code{adae} must contain the variables \code{AEBODSYS}, \code{DCSREAS}, and the variables specified by +\item \code{df} must contain the variables \code{AEBODSYS}, \code{DCSREAS}, and the variables specified by \code{arm_var}, \code{id_var}, \code{saffl_var}, \code{fmqsc_var}, and \code{fmqnam_var}. -\item If specified, \code{alt_counts_df} must contain \code{USUBJID} and the variables specified by \code{arm_var} and \code{saffl_var}. +\item If specified, \code{denominator} must contain \code{USUBJID} and the variables specified by \code{arm_var} and \code{saffl_var}. \item A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at least one record with \code{DCSREAS = "ADVERSE EVENT"}. \item \code{fmqsc_var} must contain "BROAD" or "NARROW" values, one of which will be displayed in the table. Narrow is selected by default (see \code{fmq_scope} argument). \item Flag variables (i.e. \code{XXXFL}) are expected to have two levels: \code{"Y"} (true) and \code{"N"} (false). Missing values in flag variables are treated as \code{"N"}. -\item Columns are split by arm. Overall population column is excluded by default (see \code{lbl_overall} argument). \item Numbers in table represent the absolute numbers of patients and fraction of \code{N}. -\item All-zero rows are removed by default (see \code{prune_0} argument). } } \examples{ @@ -104,7 +77,10 @@ adae <- adae \%>\% adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" -tbl <- make_table_11(adae = adae, alt_counts_df = adsl) +tbl <- make_table_11(df = adae, denominator = adsl) tbl } +\seealso{ +\code{\link{tbl_make_table_11}} +} diff --git a/man/make_table_12.Rd b/man/make_table_12.Rd index 67926716..23681c48 100644 --- a/man/make_table_12.Rd +++ b/man/make_table_12.Rd @@ -6,25 +6,21 @@ by System Organ Class and Preferred Term, Safety Population, Pooled Analyses} \usage{ make_table_12( - adae, - alt_counts_df = NULL, - show_colcounts = TRUE, + df, + denominator = NULL, + return_ard = TRUE, id_var = "USUBJID", arm_var = "ARM", saffl_var = "SAFFL", - pref_var = "AEDECOD", - lbl_overall = NULL, - risk_diff = NULL, - prune_0 = TRUE, - annotations = NULL + pref_var = "AEDECOD" ) } \arguments{ -\item{adae}{(\code{data.frame})\cr dataset (typically ADAE) required to build table.} +\item{df}{(\code{data.frame})\cr dataset required to build table.} -\item{alt_counts_df}{(\code{character})\cr alternative dataset (typically ADSL) used only to calculate column counts.} +\item{denominator}{(\code{data.frame})\cr alternative dataset (typically ADSL) used only to calculate denominator counts.} -\item{show_colcounts}{(\code{flag})\cr Whether column counts should be printed. Boolean.} +\item{return_ard}{(\code{flag})\cr whether an ARD should be returned. Defaults to \code{TRUE}.} \item{id_var}{(\code{character})\cr variable used as unique subject identifier.} @@ -33,31 +29,10 @@ make_table_12( \item{saffl_var}{(\code{character})\cr flag variable used to indicate inclusion in safety population.} \item{pref_var}{(\code{character})\cr Name of the preferred term variable from \code{adae} to include in the table.} - -\item{lbl_overall}{(\code{character})\cr if specified, an overall column will be added to the table with -the given value as the column label.} - -\item{risk_diff}{(named \code{list})\cr list of settings to apply to add one or more risk difference columns to the table. -Defaults to \code{NULL} (no risk difference column added). See \code{\link[tern:add_riskdiff]{tern::add_riskdiff()}} for more details. List should -contain the following elements: -\itemize{ -\item \code{arm_x}: (required) the name of reference arm. -\item \code{arm_y}: (required) the names of the arms to compare to the reference arm. A new column will be added for each -element of \code{arm_y}. -\item \code{col_label}: (optional) labels to use for the risk difference columns. Defaults to -\code{"Risk Difference (\%) (95\% CI)"}. For more than one risk difference column, \code{"arm x vs. arm y"} text will also -be included in the column labels by default. The length of \code{col_label} must be equal to the length of \code{arm_y}. -\item \code{pct}: (optional) whether the output should be returned as percentages. Defaults to \code{TRUE}. -}} - -\item{prune_0}{(\code{flag})\cr Whether all-zero rows should be removed from the table. Boolean.} - -\item{annotations}{(named \code{list} of \code{character})\cr list of annotations to add to the table. Valid -annotation types are \code{title}, \code{subtitles}, \code{main_footer}, and \code{prov_footer}. Each name-value pair should -use the annotation type as name and the desired string as value.} } \value{ -An \code{rtable} object. +A \code{gtsummary} table and, if \code{return_ard = TRUE}, an ARD. +If \code{return_ard = TRUE}, they will be returned as a list with named elements \code{table} and \code{ard}. } \description{ FDA Table 12: Patients With Adverse Events Leading to Treatment Discontinuation @@ -65,16 +40,14 @@ by System Organ Class and Preferred Term, Safety Population, Pooled Analyses } \details{ \itemize{ -\item \code{adae} must contain \code{DCSREAS}, \code{AESOC}, and the variables specified by \code{arm_var}, \code{id_var}, \code{saffl_var}, +\item \code{df} must contain \code{DCSREAS}, \code{AESOC}, and the variables specified by \code{arm_var}, \code{id_var}, \code{saffl_var}, and \code{pref_var}. -\item If specified, \code{alt_counts_df} must contain \code{USUBJID} and the variables specified by \code{arm_var} and \code{saffl_var}. +\item If specified, \code{denominator} must contain \code{USUBJID} and the variables specified by \code{arm_var} and \code{saffl_var}. \item A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at least one record with \code{DCSREAS = "ADVERSE EVENT"}. \item Flag variables (i.e. \code{XXXFL}) are expected to have two levels: \code{"Y"} (true) and \code{"N"} (false). Missing values in flag variables are treated as \code{"N"}. -\item Columns are split by arm. Overall population column is excluded by default (see \code{lbl_overall} argument). \item Numbers in table represent the absolute numbers of patients and fraction of \code{N}. -\item All-zero rows are removed by default (see \code{prune_0} argument). } } \examples{ @@ -82,7 +55,10 @@ adsl <- random.cdisc.data::cadsl adae <- random.cdisc.data::cadae adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" -tbl <- make_table_12(adae = adae, alt_counts_df = adsl) +tbl <- make_table_12(df = adae, denominator = adsl) tbl } +\seealso{ +\code{\link{tbl_make_table_12}} +} diff --git a/man/preproc_df_table_11.Rd b/man/preproc_df_table_11.Rd new file mode 100644 index 00000000..751aaf2b --- /dev/null +++ b/man/preproc_df_table_11.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fda-table_11.R +\name{preproc_df_table_11} +\alias{preproc_df_table_11} +\title{Pre-Process Data for Table 11 Creation} +\usage{ +preproc_df_table_11( + df, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + na_level = "" +) +} +\description{ +Pre-Process Data for Table 11 Creation +} +\keyword{internal} diff --git a/man/preproc_df_table_12.Rd b/man/preproc_df_table_12.Rd new file mode 100644 index 00000000..69c060df --- /dev/null +++ b/man/preproc_df_table_12.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fda-table_12.R +\name{preproc_df_table_12} +\alias{preproc_df_table_12} +\title{Pre-Process Data for Table 12 Creation} +\usage{ +preproc_df_table_12( + df, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD" +) +} +\description{ +Pre-Process Data for Table 12 Creation +} +\keyword{internal} diff --git a/man/tbl_make_table_11.Rd b/man/tbl_make_table_11.Rd new file mode 100644 index 00000000..46fbdf31 --- /dev/null +++ b/man/tbl_make_table_11.Rd @@ -0,0 +1,135 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fda-table_11.R +\name{tbl_make_table_11} +\alias{tbl_make_table_11} +\alias{make_table_11_gtsummary} +\alias{make_table_11_rtables} +\title{Engine-Specific Functions: Table 11} +\usage{ +make_table_11_gtsummary( + df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + na_level = "" +) + +make_table_11_rtables( + df, + alt_counts_df = NULL, + show_colcounts = TRUE, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + fmqsc_var = "FMQ01SC", + fmqnam_var = "FMQ01NAM", + fmq_scope = "NARROW", + lbl_overall = NULL, + risk_diff = NULL, + prune_0 = TRUE, + na_level = "", + annotations = NULL +) +} +\arguments{ +\item{df}{(\code{data.frame})\cr dataset required to build table.} + +\item{denominator}{(\code{data.frame})\cr alternative dataset (typically ADSL) used only to calculate denominator counts.} + +\item{id_var}{(\code{character})\cr variable used as unique subject identifier.} + +\item{arm_var}{(\code{character})\cr Name of the treatment arm variable used to split table into columns.} + +\item{saffl_var}{(\code{character})\cr flag variable used to indicate inclusion in safety population.} + +\item{fmqsc_var}{(\code{character})\cr FMQ scope variable to use in table.} + +\item{fmqnam_var}{(\code{character})\cr FMQ reference name variable to use in table.} + +\item{fmq_scope}{(\code{character})\cr FMQ scope ("NARROW" or "BROAD") to output in table.} + +\item{na_level}{(\code{character})\cr string to represent missing values.} + +\item{alt_counts_df}{(\code{character})\cr alternative dataset (typically ADSL) used only to calculate column counts.} + +\item{show_colcounts}{(\code{flag})\cr Whether column counts should be printed. Boolean.} + +\item{lbl_overall}{(\code{character})\cr if specified, an overall column will be added to the table with +the given value as the column label.} + +\item{risk_diff}{(named \code{list})\cr list of settings to apply to add one or more risk difference columns to the table. +Defaults to \code{NULL} (no risk difference column added). See \code{\link[tern:add_riskdiff]{tern::add_riskdiff()}} for more details. List should +contain the following elements: +\itemize{ +\item \code{arm_x}: (required) the name of reference arm. +\item \code{arm_y}: (required) the names of the arms to compare to the reference arm. A new column will be added for each +element of \code{arm_y}. +\item \code{col_label}: (optional) labels to use for the risk difference columns. Defaults to +\code{"Risk Difference (\%) (95\% CI)"}. For more than one risk difference column, \code{"arm x vs. arm y"} text will also +be included in the column labels by default. The length of \code{col_label} must be equal to the length of \code{arm_y}. +\item \code{pct}: (optional) whether the output should be returned as percentages. Defaults to \code{TRUE}. +}} + +\item{prune_0}{(\code{flag})\cr Whether all-zero rows should be removed from the table. Boolean.} + +\item{annotations}{(named \code{list} of \code{character})\cr list of annotations to add to the table. Valid +annotation types are \code{title}, \code{subtitles}, \code{main_footer}, and \code{prov_footer}. Each name-value pair should +use the annotation type as name and the desired string as value.} +} +\value{ +\itemize{ +\item \code{make_table_11_gtsummary()} returns a \code{gtsummary} object. +\item \code{make_table_11_rtables()} returns an \code{rtable} object. +} +} +\description{ +The table engine used by each engine-specific function is identified by its suffix. +} +\details{ +\itemize{ +\item \code{df} must contain the variables \code{AEBODSYS}, \code{DCSREAS}, and the variables specified by +\code{arm_var}, \code{id_var}, \code{saffl_var}, \code{fmqsc_var}, and \code{fmqnam_var}. +\item If specified, \code{denominator} (or \code{alt_counts_df}) must contain \code{USUBJID} and the variables specified by \code{arm_var} +and \code{saffl_var}. +\item A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at +least one record with \code{DCSREAS = "ADVERSE EVENT"}. +\item \code{fmqsc_var} must contain "BROAD" or "NARROW" values, one of which will be displayed in the table. Narrow is +selected by default (see \code{fmq_scope} argument). +\item Flag variables (i.e. \code{XXXFL}) are expected to have two levels: \code{"Y"} (true) and \code{"N"} (false). Missing values in +flag variables are treated as \code{"N"}. +\item Numbers in table represent the absolute numbers of patients and fraction of \code{N}. +\item All-zero rows are removed by default by \code{make_table_11_rtables()} (see \code{prune_0} argument). +} +} +\examples{ +library(dplyr) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae + +set.seed(1) +adae <- adae \%>\% + rename(FMQ01SC = SMQ01SC) \%>\% + mutate( + AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), + FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) + ) +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" + +# gtsummary table -------------- +tbl_gtsummary <- cardinal:::make_table_11_gtsummary(df = adae, denominator = adsl) +tbl_gtsummary + +# rtables table ---------------- +tbl_rtables <- cardinal:::make_table_11_rtables(df = adae, alt_counts_df = adsl) +tbl_rtables + +} +\seealso{ +\code{\link[=make_table_11]{make_table_11()}} +} diff --git a/man/tbl_make_table_12.Rd b/man/tbl_make_table_12.Rd new file mode 100644 index 00000000..6c960dc4 --- /dev/null +++ b/man/tbl_make_table_12.Rd @@ -0,0 +1,109 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fda-table_12.R +\name{tbl_make_table_12} +\alias{tbl_make_table_12} +\alias{make_table_12_gtsummary} +\alias{make_table_12_rtables} +\title{Engine-Specific Functions: Table 12} +\usage{ +make_table_12_gtsummary( + df, + denominator = NULL, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD" +) + +make_table_12_rtables( + df, + alt_counts_df = NULL, + show_colcounts = TRUE, + id_var = "USUBJID", + arm_var = "ARM", + saffl_var = "SAFFL", + pref_var = "AEDECOD", + lbl_overall = NULL, + risk_diff = NULL, + prune_0 = TRUE, + annotations = NULL +) +} +\arguments{ +\item{df}{(\code{data.frame})\cr dataset required to build table.} + +\item{denominator}{(\code{data.frame})\cr alternative dataset (typically ADSL) used only to calculate denominator counts.} + +\item{id_var}{(\code{character})\cr variable used as unique subject identifier.} + +\item{arm_var}{(\code{character})\cr Name of the treatment arm variable used to split table into columns.} + +\item{saffl_var}{(\code{character})\cr flag variable used to indicate inclusion in safety population.} + +\item{pref_var}{(\code{character})\cr Name of the preferred term variable from \code{adae} to include in the table.} + +\item{alt_counts_df}{(\code{character})\cr alternative dataset (typically ADSL) used only to calculate column counts.} + +\item{show_colcounts}{(\code{flag})\cr Whether column counts should be printed. Boolean.} + +\item{lbl_overall}{(\code{character})\cr if specified, an overall column will be added to the table with +the given value as the column label.} + +\item{risk_diff}{(named \code{list})\cr list of settings to apply to add one or more risk difference columns to the table. +Defaults to \code{NULL} (no risk difference column added). See \code{\link[tern:add_riskdiff]{tern::add_riskdiff()}} for more details. List should +contain the following elements: +\itemize{ +\item \code{arm_x}: (required) the name of reference arm. +\item \code{arm_y}: (required) the names of the arms to compare to the reference arm. A new column will be added for each +element of \code{arm_y}. +\item \code{col_label}: (optional) labels to use for the risk difference columns. Defaults to +\code{"Risk Difference (\%) (95\% CI)"}. For more than one risk difference column, \code{"arm x vs. arm y"} text will also +be included in the column labels by default. The length of \code{col_label} must be equal to the length of \code{arm_y}. +\item \code{pct}: (optional) whether the output should be returned as percentages. Defaults to \code{TRUE}. +}} + +\item{prune_0}{(\code{flag})\cr Whether all-zero rows should be removed from the table. Boolean.} + +\item{annotations}{(named \code{list} of \code{character})\cr list of annotations to add to the table. Valid +annotation types are \code{title}, \code{subtitles}, \code{main_footer}, and \code{prov_footer}. Each name-value pair should +use the annotation type as name and the desired string as value.} +} +\value{ +\itemize{ +\item \code{make_table_12_gtsummary()} returns a \code{gtsummary} object. +\item \code{make_table_12_rtables()} returns an \code{rtable} object. +} +} +\description{ +The table engine used by each engine-specific function is identified by its suffix. +} +\details{ +\itemize{ +\item \code{df} must contain \code{DCSREAS}, \code{AESOC}, and the variables specified by \code{arm_var}, \code{id_var}, \code{saffl_var}, +and \code{pref_var}. +\item If specified, \code{denominator} must contain \code{USUBJID} and the variables specified by \code{arm_var} and \code{saffl_var}. +\item A patient is defined as having at least one adverse event leading to treatment discontinuation when they have at +least one record with \code{DCSREAS = "ADVERSE EVENT"}. +\item Flag variables (i.e. \code{XXXFL}) are expected to have two levels: \code{"Y"} (true) and \code{"N"} (false). Missing values in +flag variables are treated as \code{"N"}. +\item Numbers in table represent the absolute numbers of patients and fraction of \code{N}. +\item All-zero rows are removed by default by \code{make_table_12_rtables()} (see \code{prune_0} argument). +} +} +\examples{ +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" + +# gtsummary table -------------- +tbl_gtsummary <- cardinal:::make_table_12_gtsummary(df = adae, denominator = adsl) +tbl_gtsummary + +# rtables table ---------------- +tbl_rtables <- cardinal:::make_table_12_rtables(df = adae, alt_counts_df = adsl) +tbl_rtables + +} +\seealso{ +\code{\link[=make_table_12]{make_table_12()}} +} diff --git a/quarto/table-templates/template-table_11.qmd b/quarto/table-templates/template-table_11.qmd index e4f37ff0..24c1f196 100644 --- a/quarto/table-templates/template-table_11.qmd +++ b/quarto/table-templates/template-table_11.qmd @@ -1,19 +1,22 @@ --- title: FDA Table 11 subtitle: Patients with FDA Medical Query (Narrow) Leading to Treatment Discontinuation, Safety Population, Pooled Analyses -format: html --- +```{r setup, echo=FALSE} +``` + ::: panel-tabset ## Spec. Screenshot ![](../assets/images/screenshots/table_11.png){fig-align="center"} -## rtables Table +## gtsummary Table -```{r tbl, message=FALSE, warning=FALSE} +
+ gtsummary Table Setup +```{r tbl2, eval=FALSE, echo=TRUE} # Load Libraries & Data -library(dplyr) library(cardinal) adsl <- random.cdisc.data::cadsl @@ -21,9 +24,9 @@ adae <- random.cdisc.data::cadae # Pre-Processing - Ensure required variables fmqsc_var and fmqnam_var exist in adae set.seed(1) -adae <- adae %>% - rename(FMQ01SC = SMQ01SC) %>% - mutate( +adae <- adae |> + dplyr::rename(FMQ01SC = SMQ01SC) |> + dplyr::mutate( AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) ) @@ -31,24 +34,116 @@ adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" # Output Table -risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") # optional -make_table_11(adae = adae, alt_counts_df = adsl, risk_diff = risk_diff) +make_table_11(df = adae, denominator = adsl, return_ard = FALSE) ``` +
+ +```{r tbl2, message=FALSE, warning=FALSE, eval=TRUE} +``` + +
+ Function Details +### `make_table_11()` + +------------------------------------------------------------------------ + +Required variables: + +- **`df`**: `USUBJID`, `AEBODSYS`, `AESER`, `DCSREAS`, and the variables specified by `arm_var`, `saffl_var`, `fmqsc_var`, and `fmqnam_var`. +- **`denominator`** (if specified): `USUBJID` and the variables specified by `arm_var` and `saffl_var`. + +| | | | +|-----------------|----------------------------------------------------------------------------------------------------------|---------------| +| **Argument** | **Description** | **Default** | +| `df` | (`data.frame`) Dataset (typically ADSL) required to build table. | *No default* | +| `return_ard` | (`flag`) Whether an ARD should be returned. | `TRUE` | +| `denominator` | (`character`) Alternative dataset used only to calculate column counts. | `NULL` | +| `id_var` | (`character`) Identifier variable used to count the participants within each flag. | `"USUBJID"` | +| `arm_var` | (`character`) Arm variable used to split table into columns. | `"ARM"` | +| `saffl_var` | (`character`) Flag variable used to indicate inclusion in safety population. | `"SAFFL"` | +| `fmqsc_var` | (`character`) FMQ scope variable to use in table. | `"FMQ01SC"` | +| `fmqnam_var` | (`character`) FMQ reference name variable to use in table. | `"FMQ01NAM"` | +| `fmq_scope` | (`character`) FMQ scope, can be '"NARROW"' or '"BROAD"'. | `"NARROW"` | +| `na_level` | (`character`) String to represent missing values. | `""` | + +Source code for this function is available [here](https://github.com/pharmaverse/cardinal/blob/main/R/fda-table_11.R). +
+ +## ARD -## rtables Table Setup +
+ ARD Setup +```{r tbl1, echo=TRUE, message=FALSE, warning=FALSE, results='hide'} +# Load Libraries & Data +library(cardinal) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae -```{r tbl, eval=FALSE, echo=TRUE} +# Pre-Processing - Ensure required variables fmqsc_var and fmqnam_var exist in adae +set.seed(1) +adae <- adae |> + dplyr::rename(FMQ01SC = SMQ01SC) |> + dplyr::mutate( + AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), + FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) + ) +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" + +# Create Table & ARD +result <- make_table_11(df = adae, denominator = adsl) + +# Output ARD +result$ard ``` +
-## Function Details +```{r tbl1-print, echo=FALSE} +withr::local_options(width = 9999) +print(result$ard, columns = "all", n = Inf) +``` -### `make_table_11()` +## rtables Table + +
+ rtables Table Setup +```{r tbl3, eval=FALSE, echo=TRUE} +# Load Libraries & Data +library(cardinal) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae + +# Pre-Processing - Ensure required variables fmqsc_var and fmqnam_var exist in adae +set.seed(1) +adae <- adae |> + dplyr::rename(FMQ01SC = SMQ01SC) |> + dplyr::mutate( + AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE), + FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE) + ) +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" +adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" + +# Output Table +risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") # optional +make_table_11_rtables(df = adae, alt_counts_df = adsl, risk_diff = risk_diff) +``` +
+ +```{r tbl3, message=FALSE, warning=FALSE, eval=TRUE} +``` + +
+ Function Details +### `make_table_11_rtables()` ------------------------------------------------------------------------ Required variables: -- **`adae`**: `USUBJID`, `AEBODSYS`, `AESER`, `DCSREAS`, and the variables specified by `arm_var`, `saffl_var`, `fmqsc_var`, and `fmqnam_var`. +- **`df`**: `USUBJID`, `AEBODSYS`, `AESER`, `DCSREAS`, and the variables specified by `arm_var`, `saffl_var`, `fmqsc_var`, and `fmqnam_var`. - **`alt_counts_df`** (if specified): `USUBJID` and the variables specified by `arm_var` and `saffl_var`. +------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+ @@ -90,4 +185,6 @@ Required variables: +------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+ Source code for this function is available [here](https://github.com/pharmaverse/cardinal/blob/main/R/fda-table_11.R). +
+ ::: diff --git a/quarto/table-templates/template-table_12.qmd b/quarto/table-templates/template-table_12.qmd index b56a7ffc..b3646f3d 100644 --- a/quarto/table-templates/template-table_12.qmd +++ b/quarto/table-templates/template-table_12.qmd @@ -1,7 +1,6 @@ --- title: FDA Table 12 subtitle: Patients With Adverse Events Leading to Treatment Discontinuation by System Organ Class and Preferred Term, Safety Population, Pooled Analyses -format: html --- ::: panel-tabset @@ -9,9 +8,11 @@ format: html ![](../assets/images/screenshots/table_12.png){fig-align="center"} -## rtables Table +## gtsummary Table -```{r tbl, message=FALSE, warning=FALSE} +
+ gtsummary Table Setup +```{r tbl2, eval=FALSE, echo=TRUE} # Load Libraries & Data library(cardinal) @@ -25,24 +26,103 @@ adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" pref_var <- "AEDECOD" # Output Table -risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") # optional -make_table_12(adae = adae, alt_counts_df = adsl, pref_var = pref_var, risk_diff = risk_diff) +make_table_12(df = adae, denominator = adsl, return_ard = FALSE, pref_var = pref_var) +``` +
+ +```{r tbl2, message=FALSE, warning=FALSE, eval=TRUE} ``` -## rtables Table Setup +
+ Function Details +### `make_table_12()` + +------------------------------------------------------------------------ + +Required variables: + +- **`df`**: `USUBJID`, `AEBODSYS`, `DCSREAS`, and the variables specified by `pref_var`, `arm_var`, and `saffl_var`. +- **`alt_counts_df`** (if specified): `USUBJID` and the variables specified by `arm_var` and `saffl_var`. + +| | | | +|-----------------|----------------------------------------------------------------------------------------------------------|---------------| +| **Argument** | **Description** | **Default** | +| `df` | (`data.frame`) Dataset (typically ADSL) required to build table. | *No default* | +| `return_ard` | (`flag`) Whether an ARD should be returned. | `TRUE` | +| `denominator` | (`character`) Alternative dataset used only to calculate column counts. | `NULL` | +| `id_var` | (`character`) Identifier variable used to count the participants within each flag. | `"USUBJID"` | +| `arm_var` | (`character`) Arm variable used to split table into columns. | `"ARM"` | +| `saffl_var` | (`character`) Flag variable used to indicate inclusion in safety population. | `"SAFFL"` | +| `pref_var` | (`character`) Name of the preferred term variable from adae to include in the table. | `"AEDECOD"` | + +Source code for this function is available [here](https://github.com/pharmaverse/cardinal/blob/main/R/fda-table_12.R). +
+ +## ARD -```{r tbl, eval=FALSE, echo=TRUE} +
+ ARD Setup +```{r tbl1, echo=TRUE, message=FALSE, warning=FALSE, results='hide'} +# Load Libraries & Data +library(cardinal) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae + +# Pre-Processing - Ensure required variable DCSREAS exist in adae +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" + +# Select Preferred Term Variable +pref_var <- "AEDECOD" + +# Create Table & ARD +result <- make_table_12(df = adae, denominator = adsl, pref_var = pref_var) + +# Output ARD +result$ard ``` +
-## Function Details +```{r tbl1-print, echo=FALSE} +withr::local_options(width = 9999) +print(result$ard, columns = "all", n = Inf) +``` -### `make_table_12()` +## rtables Table + +
+ rtables Table Setup +```{r tbl3, eval=FALSE, echo=TRUE} +# Load Libraries & Data +library(cardinal) + +adsl <- random.cdisc.data::cadsl +adae <- random.cdisc.data::cadae + +# Pre-Processing - Ensure required variable DCSREAS exist in adae +adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" + +# Select Preferred Term Variable +pref_var <- "AEDECOD" + +# Output Table +risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") # optional +make_table_12_rtables(df = adae, alt_counts_df = adsl, pref_var = pref_var, risk_diff = risk_diff) +``` +
+ +```{r tbl3, message=FALSE, warning=FALSE, eval=TRUE} +``` + +
+ Function Details +### `make_table_12_rtables()` ------------------------------------------------------------------------ Required variables: -- **`adae`**: `USUBJID`, `AEBODSYS`, `DCSREAS`, and the variables specified by `pref_var`, `arm_var`, and `saffl_var`. +- **`df`**: `USUBJID`, `AEBODSYS`, `DCSREAS`, and the variables specified by `pref_var`, `arm_var`, and `saffl_var`. - **`alt_counts_df`** (if specified): `USUBJID` and the variables specified by `arm_var` and `saffl_var`. +------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+ @@ -78,4 +158,6 @@ Required variables: +------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+ Source code for this function is available [here](https://github.com/pharmaverse/cardinal/blob/main/R/fda-table_12.R). +
+ ::: diff --git a/tests/testthat/_snaps/fda-table_11.md b/tests/testthat/_snaps/fda-table_11.md index 9131e870..edba38d6 100644 --- a/tests/testthat/_snaps/fda-table_11.md +++ b/tests/testthat/_snaps/fda-table_11.md @@ -1,38 +1,91 @@ # Table 11 generation works with default values Code - res + as.data.frame(res$table) Output - Body System or Organ Class A: Drug X B: Placebo C: Combination - FMQ (Narrow) (N=134) (N=134) (N=132) - ——————————————————————————————————————————————————————————————————————————————————————————————————— - Patients with at least one AE leading to discontinuation 83 (61.9%) 90 (67.2%) 88 (66.7%) - cl A.1 53 (39.6%) 55 (41.0%) 69 (52.3%) - FMQ1 22 (16.4%) 21 (15.7%) 37 (28.0%) - FMQ2 24 (17.9%) 31 (23.1%) 33 (25.0%) - FMQ3 28 (20.9%) 25 (18.7%) 31 (23.5%) - cl B.1 35 (26.1%) 41 (30.6%) 36 (27.3%) - FMQ1 12 (9.0%) 17 (12.7%) 19 (14.4%) - FMQ2 9 (6.7%) 21 (15.7%) 20 (15.2%) - FMQ3 19 (14.2%) 11 (8.2%) 7 (5.3%) - cl B.2 36 (26.9%) 33 (24.6%) 35 (26.5%) - FMQ1 16 (11.9%) 15 (11.2%) 12 (9.1%) - FMQ2 17 (12.7%) 12 (9.0%) 16 (12.1%) - FMQ3 11 (8.2%) 13 (9.7%) 15 (11.4%) - cl C.2 26 (19.4%) 39 (29.1%) 43 (32.6%) - FMQ1 11 (8.2%) 12 (9.0%) 19 (14.4%) - FMQ2 11 (8.2%) 15 (11.2%) 14 (10.6%) - FMQ3 8 (6.0%) 14 (10.4%) 14 (10.6%) - cl D.1 51 (38.1%) 51 (38.1%) 60 (45.5%) - FMQ1 22 (16.4%) 22 (16.4%) 32 (24.2%) - FMQ2 24 (17.9%) 25 (18.7%) 33 (25.0%) - FMQ3 19 (14.2%) 24 (17.9%) 26 (19.7%) - cl D.2 35 (26.1%) 46 (34.3%) 44 (33.3%) - FMQ1 11 (8.2%) 23 (17.2%) 17 (12.9%) - FMQ2 18 (13.4%) 16 (11.9%) 18 (13.6%) - FMQ3 11 (8.2%) 16 (11.9%) 15 (11.4%) + **Body System or Organ Class** \n    **FMQ (Narrow)** **A: Drug X** \nN = 134 **B: Placebo** \nN = 134 **C: Combination** \nN = 132 + 1 Patients with at least one AE leading to discontinuation 83 (61.9) 90 (67.2) 88 (66.7) + 2 cl A.1 53 (39.6) 55 (41.0) 69 (52.3) + 3 FMQ1 22 (16.4) 21 (15.7) 37 (28.0) + 4 FMQ2 24 (17.9) 31 (23.1) 33 (25.0) + 5 FMQ3 28 (20.9) 25 (18.7) 31 (23.5) + 6 cl B.1 35 (26.1) 41 (30.6) 36 (27.3) + 7 FMQ1 12 (9.0) 17 (12.7) 19 (14.4) + 8 FMQ2 9 (6.7) 21 (15.7) 20 (15.2) + 9 FMQ3 19 (14.2) 11 (8.2) 7 (5.3) + 10 cl B.2 36 (26.9) 33 (24.6) 35 (26.5) + 11 FMQ1 16 (11.9) 15 (11.2) 12 (9.1) + 12 FMQ2 17 (12.7) 12 (9.0) 16 (12.1) + 13 FMQ3 11 (8.2) 13 (9.7) 15 (11.4) + 14 cl C.2 26 (19.4) 39 (29.1) 43 (32.6) + 15 FMQ1 11 (8.2) 12 (9.0) 19 (14.4) + 16 FMQ2 11 (8.2) 15 (11.2) 14 (10.6) + 17 FMQ3 8 (6.0) 14 (10.4) 14 (10.6) + 18 cl D.1 51 (38.1) 51 (38.1) 60 (45.5) + 19 FMQ1 22 (16.4) 22 (16.4) 32 (24.2) + 20 FMQ2 24 (17.9) 25 (18.7) 33 (25.0) + 21 FMQ3 19 (14.2) 24 (17.9) 26 (19.7) + 22 cl D.2 35 (26.1) 46 (34.3) 44 (33.3) + 23 FMQ1 11 (8.2) 23 (17.2) 17 (12.9) + 24 FMQ2 18 (13.4) 16 (11.9) 18 (13.6) + 25 FMQ3 11 (8.2) 16 (11.9) 15 (11.4) + +--- + + Code + res$ard + Message + {cards} data frame: 162 x 13 + Output + group1 group1_level group2 group2_level variable variable_level stat_name stat_label stat + 1 ARM A: Drug X AEBODSYS cl A.1 FMQ01NAM FMQ1 n n 29 + 2 ARM A: Drug X AEBODSYS cl A.1 FMQ01NAM FMQ1 N N 134 + 3 ARM A: Drug X AEBODSYS cl A.1 FMQ01NAM FMQ1 p % 0.216 + 4 ARM B: Place… AEBODSYS cl A.1 FMQ01NAM FMQ1 n n 28 + 5 ARM B: Place… AEBODSYS cl A.1 FMQ01NAM FMQ1 N N 134 + 6 ARM B: Place… AEBODSYS cl A.1 FMQ01NAM FMQ1 p % 0.209 + 7 ARM C: Combi… AEBODSYS cl A.1 FMQ01NAM FMQ1 n n 46 + 8 ARM C: Combi… AEBODSYS cl A.1 FMQ01NAM FMQ1 N N 132 + 9 ARM C: Combi… AEBODSYS cl A.1 FMQ01NAM FMQ1 p % 0.348 + 10 ARM A: Drug X AEBODSYS cl B.1 FMQ01NAM FMQ1 n n 13 + Message + i 152 more rows + i Use `print(n = ...)` to see more rows + i 4 more variables: context, fmt_fn, warning, error + +# Table 11 generation works with gtsummary with custom values + + Code + as.data.frame(res) + Output + **Body System or Organ Class** \n    **FMQ (Narrow)** **A: Drug X** \nN = 134 **B: Placebo** \nN = 134 **C: Combination** \nN = 132 + 1 Patients with at least one AE leading to discontinuation 83 (61.9) 90 (67.2) 88 (66.7) + 2 cl A.1 53 (39.6) 55 (41.0) 69 (52.3) + 3 FMQ1 22 (16.4) 21 (15.7) 37 (28.0) + 4 FMQ2 24 (17.9) 31 (23.1) 33 (25.0) + 5 FMQ3 28 (20.9) 25 (18.7) 31 (23.5) + 6 cl B.1 35 (26.1) 41 (30.6) 36 (27.3) + 7 FMQ1 12 (9.0) 17 (12.7) 19 (14.4) + 8 FMQ2 9 (6.7) 21 (15.7) 20 (15.2) + 9 FMQ3 19 (14.2) 11 (8.2) 7 (5.3) + 10 cl B.2 36 (26.9) 33 (24.6) 35 (26.5) + 11 FMQ1 16 (11.9) 15 (11.2) 12 (9.1) + 12 FMQ2 17 (12.7) 12 (9.0) 16 (12.1) + 13 FMQ3 11 (8.2) 13 (9.7) 15 (11.4) + 14 cl C.2 26 (19.4) 39 (29.1) 43 (32.6) + 15 FMQ1 11 (8.2) 12 (9.0) 19 (14.4) + 16 FMQ2 11 (8.2) 15 (11.2) 14 (10.6) + 17 FMQ3 8 (6.0) 14 (10.4) 14 (10.6) + 18 cl D.1 51 (38.1) 51 (38.1) 60 (45.5) + 19 FMQ1 22 (16.4) 22 (16.4) 32 (24.2) + 20 FMQ2 24 (17.9) 25 (18.7) 33 (25.0) + 21 FMQ3 19 (14.2) 24 (17.9) 26 (19.7) + 22 cl D.2 35 (26.1) 46 (34.3) 44 (33.3) + 23 FMQ1 11 (8.2) 23 (17.2) 17 (12.9) + 24 FMQ2 18 (13.4) 16 (11.9) 18 (13.6) + 25 FMQ3 11 (8.2) 16 (11.9) 15 (11.4) -# Table 11 generation works with custom values +# Table 11 generation works with rtables with custom values Code res @@ -65,7 +118,7 @@ MedDRA, Medical Dictionary for Regulatory Activities; N, number of patients in treatment arm; n, number of patients with adverse event; SOC, System Organ Class -# Table 11 generation works with risk difference column +# Table 11 generation works with rtables with risk difference column Code res diff --git a/tests/testthat/_snaps/fda-table_12.md b/tests/testthat/_snaps/fda-table_12.md index 3eb8b4eb..31d10e59 100644 --- a/tests/testthat/_snaps/fda-table_12.md +++ b/tests/testthat/_snaps/fda-table_12.md @@ -1,5 +1,53 @@ # Table 12 generation works with default values + Code + as.data.frame(res$table) + Output + **Body System or Organ Class** \n    **Dictionary-Derived Term** **A: Drug X** \nN = 134 **B: Placebo** \nN = 134 **C: Combination** \nN = 132 + 1 Patients with at least one AE leading to discontinuation 86 (64.2) 93 (69.4) 90 (68.2) + 2 cl A.1 53 (39.6) 55 (41.0) 69 (52.3) + 3 dcd A.1.1.1.1 37 (27.6) 37 (27.6) 50 (37.9) + 4 dcd A.1.1.1.2 33 (24.6) 31 (23.1) 40 (30.3) + 5 cl B.1 35 (26.1) 41 (30.6) 36 (27.3) + 6 dcd B.1.1.1.1 35 (26.1) 41 (30.6) 36 (27.3) + 7 cl B.2 55 (41.0) 56 (41.8) 65 (49.2) + 8 dcd B.2.1.2.1 36 (26.9) 33 (24.6) 35 (26.5) + 9 dcd B.2.2.3.1 34 (25.4) 41 (30.6) 41 (31.1) + 10 cl C.1 28 (20.9) 36 (26.9) 32 (24.2) + 11 dcd C.1.1.1.3 28 (20.9) 36 (26.9) 32 (24.2) + 12 cl C.2 26 (19.4) 39 (29.1) 43 (32.6) + 13 dcd C.2.1.2.1 26 (19.4) 39 (29.1) 43 (32.6) + 14 cl D.1 51 (38.1) 51 (38.1) 60 (45.5) + 15 dcd D.1.1.1.1 29 (21.6) 31 (23.1) 37 (28.0) + 16 dcd D.1.1.4.2 33 (24.6) 34 (25.4) 39 (29.5) + 17 cl D.2 35 (26.1) 46 (34.3) 44 (33.3) + 18 dcd D.2.1.5.3 35 (26.1) 46 (34.3) 44 (33.3) + +--- + + Code + res$ard + Message + {cards} data frame: 90 x 13 + Output + group1 group1_level group2 group2_level variable variable_level stat_name stat_label stat + 1 ARM A: Drug X AEBODSYS cl A.1 AEDECOD dcd A.1.… n n 51 + 2 ARM A: Drug X AEBODSYS cl A.1 AEDECOD dcd A.1.… N N 134 + 3 ARM A: Drug X AEBODSYS cl A.1 AEDECOD dcd A.1.… p % 0.381 + 4 ARM B: Place… AEBODSYS cl A.1 AEDECOD dcd A.1.… n n 52 + 5 ARM B: Place… AEBODSYS cl A.1 AEDECOD dcd A.1.… N N 134 + 6 ARM B: Place… AEBODSYS cl A.1 AEDECOD dcd A.1.… p % 0.388 + 7 ARM C: Combi… AEBODSYS cl A.1 AEDECOD dcd A.1.… n n 73 + 8 ARM C: Combi… AEBODSYS cl A.1 AEDECOD dcd A.1.… N N 132 + 9 ARM C: Combi… AEBODSYS cl A.1 AEDECOD dcd A.1.… p % 0.553 + 10 ARM A: Drug X AEBODSYS cl A.1 AEDECOD dcd A.1.… n n 45 + Message + i 80 more rows + i Use `print(n = ...)` to see more rows + i 4 more variables: context, fmt_fn, warning, error + +--- + Code res Output @@ -25,6 +73,31 @@ cl D.2 35 (26.1%) 46 (34.3%) 44 (33.3%) dcd D.2.1.5.3 35 (26.1%) 46 (34.3%) 44 (33.3%) +# Table 12 generation works with gtsummary with custom values + + Code + as.data.frame(res) + Output + **Body System or Organ Class** \n    **Dictionary-Derived Term** **A: Drug X** \nN = 134 **B: Placebo** \nN = 134 **C: Combination** \nN = 132 + 1 Patients with at least one AE leading to discontinuation 86 (64.2) 93 (69.4) 90 (68.2) + 2 cl A.1 53 (39.6) 55 (41.0) 69 (52.3) + 3 dcd A.1.1.1.1 37 (27.6) 37 (27.6) 50 (37.9) + 4 dcd A.1.1.1.2 33 (24.6) 31 (23.1) 40 (30.3) + 5 cl B.1 35 (26.1) 41 (30.6) 36 (27.3) + 6 dcd B.1.1.1.1 35 (26.1) 41 (30.6) 36 (27.3) + 7 cl B.2 55 (41.0) 56 (41.8) 65 (49.2) + 8 dcd B.2.1.2.1 36 (26.9) 33 (24.6) 35 (26.5) + 9 dcd B.2.2.3.1 34 (25.4) 41 (30.6) 41 (31.1) + 10 cl C.1 28 (20.9) 36 (26.9) 32 (24.2) + 11 dcd C.1.1.1.3 28 (20.9) 36 (26.9) 32 (24.2) + 12 cl C.2 26 (19.4) 39 (29.1) 43 (32.6) + 13 dcd C.2.1.2.1 26 (19.4) 39 (29.1) 43 (32.6) + 14 cl D.1 51 (38.1) 51 (38.1) 60 (45.5) + 15 dcd D.1.1.1.1 29 (21.6) 31 (23.1) 37 (28.0) + 16 dcd D.1.1.4.2 33 (24.6) 34 (25.4) 39 (29.5) + 17 cl D.2 35 (26.1) 46 (34.3) 44 (33.3) + 18 dcd D.2.1.5.3 35 (26.1) 46 (34.3) 44 (33.3) + # Table 12 generation works with custom values Code diff --git a/tests/testthat/test-fda-table_11.R b/tests/testthat/test-fda-table_11.R index d4d76828..754b051f 100644 --- a/tests/testthat/test-fda-table_11.R +++ b/tests/testthat/test-fda-table_11.R @@ -12,16 +12,41 @@ adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW" test_that("Table 11 generation works with default values", { - result <- make_table_11(adae = adae, alt_counts_df = adsl) + withr::local_options(list(width = 150)) + expect_warning(result <- make_table_11(adae, adsl)) res <- expect_silent(result) - expect_snapshot(res) + expect_snapshot(res$table |> as.data.frame()) + expect_snapshot(res$ard) + + # no ARD + expect_warning(result2 <- make_table_11(adae, adsl, return_ard = FALSE)) + res2 <- expect_silent(result2) + + # tables the same + expect_identical(res$table, res2) }) -test_that("Table 11 generation works with custom values", { +# gtsummary ---- + +test_that("Table 11 generation works with gtsummary with custom values", { + withr::local_options(list(width = 150)) + + result <- make_table_11_gtsummary( + df = adae, + denominator = adsl + ) + + res <- expect_silent(result) + expect_snapshot(res |> as.data.frame()) +}) + +# rtables ---- + +test_that("Table 11 generation works with rtables with custom values", { adae <- formatters::var_relabel(adae, AEBODSYS = "Body System or Organ Class(2)") - result <- make_table_11( - adae = adae, + result <- make_table_11_rtables( + df = adae, alt_counts_df = adsl, fmq_scope = "BROAD", annotations = list( @@ -48,9 +73,9 @@ test_that("Table 11 generation works with custom values", { expect_snapshot(res) }) -test_that("Table 11 generation works with risk difference column", { +test_that("Table 11 generation works with rtables with risk difference column", { risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") - result <- make_table_11(adae, adsl, risk_diff = risk_diff) + result <- make_table_11_rtables(adae, adsl, risk_diff = risk_diff) res <- expect_silent(result) expect_snapshot(res) diff --git a/tests/testthat/test-fda-table_12.R b/tests/testthat/test-fda-table_12.R index 1e3e2a98..4c39a290 100644 --- a/tests/testthat/test-fda-table_12.R +++ b/tests/testthat/test-fda-table_12.R @@ -3,7 +3,39 @@ adae <- adae_raw adae$DCSREAS[is.na(adae$DCSREAS)] <- "ADVERSE EVENT" test_that("Table 12 generation works with default values", { - result <- make_table_12(adae = adae, alt_counts_df = adsl) + withr::local_options(list(width = 150)) + + expect_warning(result <- make_table_12(adae, adsl)) + res <- expect_silent(result) + expect_snapshot(res$table |> as.data.frame()) + expect_snapshot(res$ard) + + # no ARD + expect_warning(result2 <- make_table_12(adae, adsl, return_ard = FALSE)) + res2 <- expect_silent(result2) + + # tables the same + expect_identical(res$table, res2) +}) + +# gtsummary ---- + +test_that("Table 12 generation works with gtsummary with custom values", { + withr::local_options(list(width = 150)) + + result <- make_table_12_gtsummary( + df = adae, + denominator = adsl + ) + + res <- expect_silent(result) + expect_snapshot(res |> as.data.frame()) +}) + +# rtables ---- + +test_that("Table 12 generation works with default values", { + result <- make_table_12_rtables(df = adae, alt_counts_df = adsl) res <- expect_silent(result) expect_snapshot(res) @@ -11,8 +43,8 @@ test_that("Table 12 generation works with default values", { test_that("Table 12 generation works with custom values", { adae <- var_relabel(adae, AEDECOD = "Preferred Term") - result <- make_table_12( - adae = adae, + result <- make_table_12_rtables( + df = adae, alt_counts_df = adsl, annotations = list( title = paste( @@ -41,7 +73,7 @@ test_that("Table 12 generation works with custom values", { test_that("Table 12 generation works with risk difference column", { risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") - result <- make_table_12(adae, adsl, risk_diff = risk_diff) + result <- make_table_12_rtables(adae, adsl, risk_diff = risk_diff) res <- expect_silent(result) expect_snapshot(res)