diff --git a/NEWS.md b/NEWS.md index 15155eda58..ca72854ad8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,6 @@ # teal.modules.clinical 0.8.14.9020 ### Breaking changes - * Replaced `chunks` with simpler `qenv` class. * Replaced `datasets` argument containing `FilteredData` with the new arguments `data` (`tdata` object) and `filter_panel_api` (`FilterPanelAPI`). @@ -13,10 +12,13 @@ * Added adjustment method choice to `tm_a_mmrm` to allow for Kenward-Roger adjustment of standard errors and p-values. ### Miscellaneous -* Package now uses `scda.2022` rather than `scda.2021` in SUGGESTS. +* Package now uses `scda.2022` rather than `scda.2021` in SUGGESTS. * Removed unused argument `param` from `tm_g_pp_vitals`. * Removed optimizer choice from `tm_a_mmrm` since we can just always use the automatically determined optimizer. +* Creation of internal data for `adsl`, `adae`, `adlb`, `adcm`, `adrs`, and `adtte`. They are accessible + via `tmc_ex_*` prefix. +* Partial substitution of `scda` data with internal data in examples. # teal.modules.clinical 0.8.14 diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000000..f67fac4151 --- /dev/null +++ b/R/data.R @@ -0,0 +1,29 @@ +#' Simulated CDISC Data for Examples +#' +#' @format `rds` (`data.frame`) +#' +#' @name ex_data +NULL + +#' @describeIn ex_data ADSL data +#' +"tmc_ex_adsl" + +#' @describeIn ex_data ADAE data +#' +"tmc_ex_adae" + +#' @describeIn ex_data ADLB data +#' +"tmc_ex_adlb" + +#' @describeIn ex_data ADRS data +#' +"tmc_ex_adrs" + +#' @describeIn ex_data ADTTE data +#' +"tmc_ex_adtte" +#' @describeIn ex_data ADCM data +#' +"tmc_ex_adcm" diff --git a/R/tm_a_gee.R b/R/tm_a_gee.R index 1c92d94215..bfbaee3cd8 100644 --- a/R/tm_a_gee.R +++ b/R/tm_a_gee.R @@ -145,9 +145,7 @@ template_a_gee <- function(output_table, #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'synthetic_cdisc_dataset("latest", "adsl")' -#' ), +#' cdisc_dataset("ADSL", ADSL), #' cdisc_dataset("ADQS", ADQS, #' code = 'ADQS <- synthetic_cdisc_dataset("latest", "adqs") %>% #' dplyr::filter(ABLFL != "Y" & ABLFL2 != "Y") %>% diff --git a/R/tm_a_mmrm.R b/R/tm_a_mmrm.R index a3d9cc5892..be67c09217 100644 --- a/R/tm_a_mmrm.R +++ b/R/tm_a_mmrm.R @@ -451,7 +451,6 @@ template_mmrm_plots <- function(fit_name, #' numerical precision. #' #' @examples -#' #' library(scda) #' #' ADSL <- synthetic_cdisc_dataset("latest", "adsl") diff --git a/R/tm_g_barchart_simple.R b/R/tm_g_barchart_simple.R index 3a9329b450..804aad3f6c 100644 --- a/R/tm_g_barchart_simple.R +++ b/R/tm_g_barchart_simple.R @@ -15,11 +15,11 @@ #' #' @examples #' library(dplyr) -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADAE <- synthetic_cdisc_dataset("latest", "adae") +#' ADSL <- tmc_ex_adsl %>% +#' dplyr::mutate(ITTFL = factor("Y")) +#' ADAE <- tmc_ex_adae #' #' adae_labels <- formatters::var_labels(ADAE, fill = FALSE) #' ADAE <- ADAE %>% dplyr::filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X"))) @@ -29,15 +29,8 @@ #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), -#' cdisc_dataset("ADAE", ADAE, -#' code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae") -#' adae_labels <- formatters::var_labels(ADAE, fill = FALSE) -#' ADAE <- ADAE %>% -#' dplyr::filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X"))) -#' formatters::var_labels(ADAE) <- adae_labels -#' ADAE' -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADAE", ADAE) #' ), #' modules = modules( #' tm_g_barchart_simple( diff --git a/R/tm_g_ci.R b/R/tm_g_ci.R index 4df7ba3d02..1b90c30126 100644 --- a/R/tm_g_ci.R +++ b/R/tm_g_ci.R @@ -188,19 +188,17 @@ template_g_ci <- function(dataname, # nolint #' and point shape). #' #' @export -#' @examples #' -#' library(scda) +#' @examples #' library(nestcolor) -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADLB <- synthetic_cdisc_dataset("latest", "adlb") +#' +#' ADSL <- tmc_ex_adsl +#' ADLB <- tmc_ex_adlb #' #' app <- init( #' data = cdisc_data( #' cdisc_dataset("ADSL", ADSL), -#' cdisc_dataset("ADLB", ADLB), -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADLB <- synthetic_cdisc_dataset("latest", "adlb")' # nolint +#' cdisc_dataset("ADLB", ADLB) #' ), #' modules = modules( #' tm_g_ci( diff --git a/R/tm_g_forest_rsp.R b/R/tm_g_forest_rsp.R index ba6049f58c..142478f541 100644 --- a/R/tm_g_forest_rsp.R +++ b/R/tm_g_forest_rsp.R @@ -215,14 +215,12 @@ template_forest_rsp <- function(dataname = "ANL", #' @template author_song24 #' #' @examples -#' -#' library(scda) #' library(dplyr) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADRS <- synthetic_cdisc_dataset("latest", "adrs") %>% -#' mutate(AVALC = d_onco_rsp_label(AVALC)) %>% +#' ADSL <- tmc_ex_adsl +#' ADRS <- tmc_ex_adrs %>% +#' mutate(AVALC = tern::d_onco_rsp_label(AVALC)) %>% #' filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP") #' #' arm_ref_comp <- list( @@ -239,12 +237,7 @@ template_forest_rsp <- function(dataname = "ANL", #' app <- init( #' data = cdisc_data( #' cdisc_dataset("ADSL", ADSL), -#' cdisc_dataset("ADRS", ADRS), -#' code = -#' 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADRS <- synthetic_cdisc_dataset("latest", "adrs") %>% -#' mutate(AVALC = d_onco_rsp_label(AVALC)) %>% -#' filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")' # nolint +#' cdisc_dataset("ADRS", ADRS) #' ), #' modules = modules( #' tm_g_forest_rsp( diff --git a/R/tm_g_forest_tte.R b/R/tm_g_forest_tte.R index 4e7b58b81b..eae683c572 100644 --- a/R/tm_g_forest_tte.R +++ b/R/tm_g_forest_tte.R @@ -224,11 +224,10 @@ template_forest_tte <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +#' ADSL <- tmc_ex_adsl +#' ADTTE <- tmc_ex_adtte #' #' ADSL$RACE <- droplevels(ADSL$RACE) #' @@ -245,15 +244,8 @@ template_forest_tte <- function(dataname = "ANL", #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset( -#' "ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADSL$RACE <- droplevels(ADSL$RACE)' # nolint -#' ), -#' cdisc_dataset( -#' "ADTTE", ADTTE, -#' code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")' -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADTTE", ADTTE) #' ), #' modules = modules( #' tm_g_forest_tte( diff --git a/R/tm_g_ipp.R b/R/tm_g_ipp.R index 645470eddb..026d81635c 100644 --- a/R/tm_g_ipp.R +++ b/R/tm_g_ipp.R @@ -187,11 +187,10 @@ template_g_ipp <- function(dataname = "ANL", #' #' @examples #' library(dplyr) -#' library(scda) #' library(nestcolor) #' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") %>% slice(1:20) -#' adlb <- synthetic_cdisc_dataset("latest", "adlb") +#' adsl <- tmc_ex_adsl %>% slice(1:20) +#' adlb <- tmc_ex_adlb #' adlb <- adlb %>% filter(USUBJID %in% adsl$USUBJID) #' #' adsl <- df_explicit_na(adsl) @@ -202,16 +201,11 @@ template_g_ipp <- function(dataname = "ANL", #' data = cdisc_data( #' cdisc_dataset( #' "ADSL", -#' adsl, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") %>% slice(1:20) -#' ADSL <- df_explicit_na(ADSL)' # nolint +#' adsl #' ), #' cdisc_dataset( #' "ADLB", -#' adlb, -#' code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") -#' ADLB <- df_explicit_na(ADLB) %>% -#' dplyr::filter(AVISIT != "SCREENING")' # nolint +#' adlb #' ) #' ), #' modules = modules( diff --git a/R/tm_g_km.R b/R/tm_g_km.R index aabd9d9e90..a123045b04 100644 --- a/R/tm_g_km.R +++ b/R/tm_g_km.R @@ -239,11 +239,10 @@ template_g_km <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +#' ADSL <- tmc_ex_adsl +#' ADTTE <- tmc_ex_adtte #' #' arm_ref_comp <- list( #' ACTARMCD = list( @@ -258,8 +257,8 @@ template_g_km <- function(dataname = "ANL", #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), -#' cdisc_dataset("ADTTE", ADTTE, code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")') +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADTTE", ADTTE) #' ), #' modules = modules( #' tm_g_km( diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index c2c91bf2ce..a5a3494f7e 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -203,23 +203,17 @@ template_g_lineplot <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADLB <- synthetic_cdisc_dataset("latest", "adlb") +#' ADSL <- tmc_ex_adsl +#' ADLB <- tmc_ex_adlb #' #' ADLB <- dplyr::mutate(ADLB, AVISIT == forcats::fct_reorder(AVISIT, AVISITN, min)) #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADLB", ADLB, -#' code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") -#' ADLB <- dplyr::mutate(ADLB, AVISIT == forcats::fct_reorder(AVISIT, AVISITN, min))' # nolint -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADLB", ADLB) #' ), #' modules = modules( #' tm_g_lineplot( diff --git a/R/tm_g_pp_adverse_events.R b/R/tm_g_pp_adverse_events.R index 3be70305f7..007748589d 100644 --- a/R/tm_g_pp_adverse_events.R +++ b/R/tm_g_pp_adverse_events.R @@ -180,20 +180,15 @@ template_adverse_events <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADAE <- synthetic_cdisc_dataset("latest", "adae") +#' ADSL <- tmc_ex_adsl +#' ADAE <- tmc_ex_adae #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADAE", ADAE, -#' code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")' -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADAE", ADAE) #' ), #' modules = modules( #' tm_g_pp_adverse_events( diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index d1c30090b6..bf17fec65a 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -354,14 +354,13 @@ template_patient_timeline <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADAE <- synthetic_cdisc_dataset("latest", "adae") -#' ADCM <- synthetic_cdisc_dataset("latest", "adcm") +#' ADSL <- tmc_ex_adsl +#' ADAE <- tmc_ex_adae +#' ADCM <- tmc_ex_adcm #' -#' #' Modify ADCM +#' # Modify ADCM #' ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) #' ADCM$CMDOSE <- 1 #' ADCM$CMDOSU <- "U" diff --git a/R/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index 81acc30b69..3c1fdd8cee 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -253,13 +253,12 @@ template_therapy <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) #' library(nestcolor) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADCM <- synthetic_cdisc_dataset("latest", "adcm") +#' ADSL <- tmc_ex_adsl +#' ADCM <- tmc_ex_adcm #' -#' #' Modify ADCM +#' # Modify ADCM #' ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) #' ADCM$CMDOSE <- 1 #' ADCM$CMTRT <- ADCM$CMCAT @@ -280,26 +279,8 @@ template_therapy <- function(dataname = "ANL", #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), +#' cdisc_dataset("ADSL", ADSL), #' cdisc_dataset("ADCM", ADCM, -#' code = 'ADCM <- synthetic_cdisc_dataset("latest", "adcm") -#' ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) -#' ADCM$CMDOSE <- 1 -#' ADCM$CMTRT <- ADCM$CMCAT -#' ADCM$CMDOSU <- "U" -#' ADCM$CMROUTE <- "CMROUTE" -#' ADCM$CMDOSFRQ <- "CMDOSFRQ" -#' ADCM$CMASTDTM <- ADCM$ASTDTM -#' ADCM$CMAENDTM <- ADCM$AENDTM -#' formatters::var_labels( -#' ADCM[c("CMINDC", "CMTRT", "ASTDY", "AENDY")]) <- c( -#' "Indication", -#' "Reported Name of Drug, Med, or Therapy", -#' "Study Day of Start of Medication", -#' "Study Day of End of Medication") -#' ADCM', #' keys = adcm_keys #' ) #' ), diff --git a/R/tm_g_pp_vitals.R b/R/tm_g_pp_vitals.R index c03dcc5398..85244a171e 100644 --- a/R/tm_g_pp_vitals.R +++ b/R/tm_g_pp_vitals.R @@ -191,6 +191,7 @@ template_vitals <- function(dataname = "ANL", #' @examples #' library(scda) #' library(nestcolor) +#' #' ADSL <- synthetic_cdisc_dataset("latest", "adsl") #' ADVS <- synthetic_cdisc_dataset("latest", "advs") #' diff --git a/R/tm_t_abnormality.R b/R/tm_t_abnormality.R index 103954ad02..cd7c357d72 100644 --- a/R/tm_t_abnormality.R +++ b/R/tm_t_abnormality.R @@ -232,35 +232,23 @@ template_abnormality <- function(parentname, #' #' @export #' @examples -#' library(scda) #' library(dplyr) #' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adlb <- synthetic_cdisc_dataset("latest", "adlb") %>% +#' adsl <- tmc_ex_adsl +#' adlb <- tmc_ex_adlb %>% #' mutate( #' ONTRTFL = case_when( #' AVISIT %in% c("SCREENING", "BASELINE") ~ "", #' TRUE ~ "Y" #' ) #' ) +#' #' attr(adlb[["ONTRTFL"]], "label") <- "On Treatment Record Flag" #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADLB", adlb, -#' code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") %>% -#' mutate( -#' ONTRTFL = case_when( -#' AVISIT %in% c("SCREENING", "BASELINE") ~ "", -#' TRUE ~ "Y" -#' ) -#' ) -#' attr(ADLB[["ONTRTFL"]], "label") <- "On Treatment Record Flag" -#' ADLB' -#' ) +#' cdisc_dataset("ADSL", adsl), +#' cdisc_dataset("ADLB", adlb) #' ), #' modules = modules( #' tm_t_abnormality( @@ -276,6 +264,10 @@ template_abnormality <- function(parentname, #' selected = c("LBCAT", "PARAM"), #' keep_order = TRUE #' ), +#' baseline_var = teal.transform::choices_selected( +#' teal.transform::variable_choices(adlb, subset = "BNRIND"), +#' selected = "BNRIND", fixed = TRUE +#' ), #' grade = choices_selected( #' choices = variable_choices(adlb, subset = "ANRIND"), #' selected = "ANRIND", diff --git a/R/tm_t_abnormality_by_worst_grade.R b/R/tm_t_abnormality_by_worst_grade.R index 7bedfb5426..3cfc165530 100644 --- a/R/tm_t_abnormality_by_worst_grade.R +++ b/R/tm_t_abnormality_by_worst_grade.R @@ -226,22 +226,16 @@ template_abnormality_by_worst_grade <- function(parentname, # nolint #' @export #' #' @examples -#' library(scda) #' library(dplyr) #' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adlb <- synthetic_cdisc_dataset("latest", "adlb") %>% +#' adsl <- tmc_ex_adsl +#' adlb <- tmc_ex_adlb %>% #' filter(!AVISIT %in% c("SCREENING", "BASELINE")) #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADLB", adlb, -#' code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") %>% -#' filter(!AVISIT %in% c("SCREENING", "BASELINE"))' # nolint -#' ) +#' cdisc_dataset("ADSL", adsl), +#' cdisc_dataset("ADLB", adlb) #' ), #' modules = modules( #' tm_t_abnormality_by_worst_grade( diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index 07778b0392..4a43b9a87b 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -429,10 +429,10 @@ template_ancova <- function(dataname = "ANL", #' @export #' #' @examples -#' #' # Preparation of the test case. #' library(dplyr) #' library(scda) +#' #' adsl <- synthetic_cdisc_dataset("latest", "adsl") #' adqs <- synthetic_cdisc_dataset("latest", "adqs") #' diff --git a/R/tm_t_binary_outcome.R b/R/tm_t_binary_outcome.R index 2961096b09..dfe633ee5a 100644 --- a/R/tm_t_binary_outcome.R +++ b/R/tm_t_binary_outcome.R @@ -16,11 +16,8 @@ #' @examples #' if (interactive()) { #' # Preparation of the test case. -#' library(dplyr) -#' library(scda) -#' library(tern) -#' adsl <- synthetic_cdisc_data("latest")$adsl -#' adrs <- synthetic_cdisc_data("latest")$adrs +#' adsl <- tmc_ex_adsl +#' adrs <- tmc_ex_adrs #' #' # Generate an expression for the analysis of responders. #' a <- template_binary_outcome( @@ -395,10 +392,9 @@ template_binary_outcome <- function(dataname, #' #' @examples #' library(dplyr) -#' library(scda) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADRS <- synthetic_cdisc_dataset("latest", "adrs") %>% +#' ADSL <- tmc_ex_adsl +#' ADRS <- tmc_ex_adrs %>% #' mutate(AVALC = d_onco_rsp_label(AVALC)) %>% #' filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP") #' arm_ref_comp <- list( @@ -408,12 +404,7 @@ template_binary_outcome <- function(dataname, #' app <- init( #' data = cdisc_data( #' cdisc_dataset("ADSL", ADSL), -#' cdisc_dataset("ADRS", ADRS), -#' code = -#' 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADRS <- synthetic_cdisc_dataset("latest", "adrs") %>% -#' mutate(AVALC = d_onco_rsp_label(AVALC)) %>% -#' filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")' # nolint +#' cdisc_dataset("ADRS", ADRS) #' ), #' modules = modules( #' tm_t_binary_outcome( diff --git a/R/tm_t_coxreg.R b/R/tm_t_coxreg.R index 4c5c6bc8db..8897fcde13 100644 --- a/R/tm_t_coxreg.R +++ b/R/tm_t_coxreg.R @@ -413,10 +413,8 @@ template_coxreg_m <- function(dataname, #' ## The example below is based on the usual approach involving creation of #' ## a random CDISC dataset and then running the application. #' -#' library(scda) -#' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +#' ADSL <- tmc_ex_adsl +#' ADTTE <- tmc_ex_adtte #' arm_ref_comp <- list( #' ACTARMCD = list( #' ref = "ARM B", @@ -430,12 +428,8 @@ template_coxreg_m <- function(dataname, #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADTTE", ADTTE, -#' code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")' -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADTTE", ADTTE) #' ), #' modules = modules( #' tm_t_coxreg( diff --git a/R/tm_t_events.R b/R/tm_t_events.R index f067ffcd1d..7d6b895a17 100644 --- a/R/tm_t_events.R +++ b/R/tm_t_events.R @@ -446,15 +446,14 @@ template_events <- function(dataname, #' #' @examples #' library(dplyr) -#' library(scda) #' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adae <- synthetic_cdisc_dataset("latest", "adae") +#' adsl <- tmc_ex_adsl +#' adae <- tmc_ex_adae #' #' app <- teal::init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), -#' cdisc_dataset("ADAE", adae, code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")') +#' cdisc_dataset("ADSL", adsl), +#' cdisc_dataset("ADAE", adae) #' ), #' modules = modules( #' tm_t_events( diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 57510aa7e0..8721c744a7 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -778,16 +778,16 @@ template_events_col_by_grade <- function(dataname, #' @export #' @examples #' library(dplyr) -#' library(scda) #' library(tern) #' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adae <- synthetic_cdisc_dataset("latest", "adae") +#' adsl <- tmc_ex_adsl +#' adae <- tmc_ex_adae %>% +#' mutate_if(is.character, as.factor) # be certain of having factors #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), -#' cdisc_dataset("ADAE", adae, code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")') +#' cdisc_dataset("ADSL", adsl), +#' cdisc_dataset("ADAE", adae) #' ), #' modules = modules( #' tm_t_events_by_grade( diff --git a/R/tm_t_events_summary.R b/R/tm_t_events_summary.R index da9fd9cce0..2651a03494 100644 --- a/R/tm_t_events_summary.R +++ b/R/tm_t_events_summary.R @@ -492,9 +492,8 @@ template_events_summary <- function(anl_name, #' @export #' @examples #' library(dplyr) -#' library(scda) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") %>% +#' ADSL <- tmc_ex_adsl %>% #' mutate( #' DTHFL = case_when( # nolint #' !is.na(DTHDT) ~ "Y", @@ -503,7 +502,7 @@ template_events_summary <- function(anl_name, #' ) #' attr(ADSL[["DTHFL"]], "label") <- "Subject Death Flag" #' -#' ADAE <- synthetic_cdisc_dataset("latest", "adae") +#' ADAE <- tmc_ex_adae #' #' add_event_flags <- function(dat) { #' dat <- dat %>% @@ -535,45 +534,8 @@ template_events_summary <- function(anl_name, #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = -#' 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") %>% -#' mutate( -#' DTHFL = case_when( # nolint -#' !is.na(DTHDT) ~ "Y", -#' TRUE ~ "" -#' ) -#' ) -#' attr(ADSL[["DTHFL"]], "label") <- "Subject Death Flag" -#' ADSL' -#' ), -#' cdisc_dataset("ADAE", ADAE, -#' code = -#' 'ADAE <- synthetic_cdisc_dataset("latest", "adae") -#' add_event_flags <- function(dat) { -#' dat <- dat %>% -#' dplyr::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"]]) -#' ) -#' formatters::var_labels(dat)[names(column_labels)] <- as.character(column_labels) -#' dat -#' } -#' # Generating user-defined event flags. -#' ADAE <- ADAE %>% add_event_flags()' # nolint -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADAE", ADAE) #' ), #' modules = modules( #' tm_t_events_summary( diff --git a/R/tm_t_logistic.R b/R/tm_t_logistic.R index 8508408f58..53b6e81e5a 100644 --- a/R/tm_t_logistic.R +++ b/R/tm_t_logistic.R @@ -229,11 +229,10 @@ template_logistic <- function(dataname, #' #' @export #' @examples -#' library(scda) #' library(dplyr) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADRS <- synthetic_cdisc_dataset("latest", "adrs") %>% +#' ADSL <- tmc_ex_adsl +#' ADRS <- tmc_ex_adrs %>% #' filter(PARAMCD %in% c("BESRSPI", "INVET")) #' #' arm_ref_comp <- list( @@ -249,13 +248,8 @@ template_logistic <- function(dataname, #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADRS", ADRS, -#' code = 'ADRS <- synthetic_cdisc_dataset("latest", "adrs") %>% -#' filter(PARAMCD %in% c("BESRSPI", "INVET"))' # nolint -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADRS", ADRS) #' ), #' modules = modules( #' tm_t_logistic( diff --git a/R/tm_t_mult_events.R b/R/tm_t_mult_events.R index 9fd7ada44d..66fbe71fc0 100644 --- a/R/tm_t_mult_events.R +++ b/R/tm_t_mult_events.R @@ -280,17 +280,15 @@ template_mult_events <- function(dataname, #' #' @examples #' library(dplyr) -#' library(scda) #' -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADCM <- synthetic_cdisc_dataset("latest", "adcm") +#' ADSL <- tmc_ex_adsl +#' ADCM <- tmc_ex_adcm #' adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4") #' #' app <- teal::init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), +#' cdisc_dataset("ADSL", ADSL), #' cdisc_dataset("ADCM", ADCM, -#' code = 'ADCM <- synthetic_cdisc_dataset("latest", "adcm")', #' keys = adcm_keys #' ) #' ), diff --git a/R/tm_t_pp_basic_info.R b/R/tm_t_pp_basic_info.R index e4f316a343..899cb72e72 100644 --- a/R/tm_t_pp_basic_info.R +++ b/R/tm_t_pp_basic_info.R @@ -55,13 +55,11 @@ template_basic_info <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") +#' ADSL <- tmc_ex_adsl #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), -#' check = TRUE +#' cdisc_dataset("ADSL", ADSL) #' ), #' modules = modules( #' tm_t_pp_basic_info( diff --git a/R/tm_t_pp_laboratory.R b/R/tm_t_pp_laboratory.R index 8fe19fc9e2..a16f9488b4 100644 --- a/R/tm_t_pp_laboratory.R +++ b/R/tm_t_pp_laboratory.R @@ -108,18 +108,15 @@ template_laboratory <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADLB <- synthetic_cdisc_dataset("latest", "adlb") +#' +#' # Reduced data for tests +#' ADSL <- tmc_ex_adsl +#' ADLB <- tmc_ex_adlb #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADLB", ADLB, -#' code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb")' -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADLB", ADLB) #' ), #' modules = modules( #' tm_t_pp_laboratory( diff --git a/R/tm_t_pp_prior_medication.R b/R/tm_t_pp_prior_medication.R index 8d4221c458..5f9088fdf5 100644 --- a/R/tm_t_pp_prior_medication.R +++ b/R/tm_t_pp_prior_medication.R @@ -72,11 +72,10 @@ template_prior_medication <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADCM <- synthetic_cdisc_dataset("latest", "adcm") +#' ADSL <- tmc_ex_adsl +#' ADCM <- tmc_ex_adcm #' -#' #' Modify ADCM +#' # Modify ADCM #' ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) #' ADCM$CMDOSE <- 1 #' ADCM$CMTRT <- ADCM$CMCAT @@ -96,25 +95,8 @@ template_prior_medication <- function(dataname = "ANL", #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), +#' cdisc_dataset("ADSL", ADSL), #' cdisc_dataset("ADCM", ADCM, -#' code = 'ADCM <- synthetic_cdisc_dataset("latest", "adcm") -#' ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) -#' ADCM$CMDOSE <- 1 -#' ADCM$CMTRT <- ADCM$CMCAT -#' ADCM$CMDOSU <- "U" -#' ADCM$CMROUTE <- "CMROUTE" -#' ADCM$CMDOSFRQ <- "CMDOSFRQ" -#' ADCM$CMASTDTM <- ADCM$ASTDTM -#' ADCM$CMAENDTM <- ADCM$AENDTM -#' formatters::var_labels( -#' ADCM[c("CMINDC", "CMTRT", "ASTDY")]) <- c( -#' "Indication", -#' "Reported Name of Drug, Med, or Therapy", -#' "Study Day of Start of Medication" -#' )', #' keys = adcm_keys #' ) #' ), diff --git a/R/tm_t_shift_by_arm_by_worst.R b/R/tm_t_shift_by_arm_by_worst.R index 5e18bde679..78282d3d93 100644 --- a/R/tm_t_shift_by_arm_by_worst.R +++ b/R/tm_t_shift_by_arm_by_worst.R @@ -171,8 +171,8 @@ template_shift_by_arm_by_worst <- function(dataname, #' whether to include row with total number of patients. #' #' @export -#' @examples #' +#' @examples #' library(dplyr) #' library(tern) #' library(scda) diff --git a/R/tm_t_shift_by_grade.R b/R/tm_t_shift_by_grade.R index da0531d3d8..a4bef39281 100644 --- a/R/tm_t_shift_by_grade.R +++ b/R/tm_t_shift_by_grade.R @@ -472,20 +472,13 @@ template_shift_by_grade <- function(parentname, #' #' @export #' @examples -#' library(scda) -#' library(dplyr) -#' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adlb <- synthetic_cdisc_dataset("latest", "adlb") +#' adsl <- tmc_ex_adsl +#' adlb <- tmc_ex_adlb #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADLB", adlb, -#' code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb")' -#' ) +#' cdisc_dataset("ADSL", adsl), +#' cdisc_dataset("ADLB", adlb) #' ), #' modules = modules( #' tm_t_shift_by_grade( diff --git a/R/tm_t_smq.R b/R/tm_t_smq.R index a8608dfbb4..d84bc1cb0e 100644 --- a/R/tm_t_smq.R +++ b/R/tm_t_smq.R @@ -315,10 +315,8 @@ template_smq <- function(dataname, #' @export #' #' @examples -#' library(scda) -#' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adae <- synthetic_cdisc_dataset("latest", "adae") +#' adsl <- tmc_ex_adsl +#' adae <- tmc_ex_adae #' #' names_baskets <- grep("^(SMQ|CQ).*NAM$", names(adae), value = TRUE) #' names_scopes <- grep("^SMQ.*SC$", names(adae), value = TRUE) @@ -336,12 +334,8 @@ template_smq <- function(dataname, #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADAE", adae, -#' code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")' -#' ) +#' cdisc_dataset("ADSL", adsl), +#' cdisc_dataset("ADAE", adae) #' ), #' modules = modules( #' tm_t_smq( diff --git a/R/tm_t_summary.R b/R/tm_t_summary.R index e5ac78b6b2..3941e58165 100644 --- a/R/tm_t_summary.R +++ b/R/tm_t_summary.R @@ -219,12 +219,9 @@ template_summary <- function(dataname, #' #' @export #' @examples -#' # Preparation of the test case. -#' library(dplyr) -#' library(scda) -#' library(tern) -#' -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") +#' # Preparation of the test case +#' adsl <- tmc_ex_adsl +#' adsl$EOSDY[1] <- NA_integer_ #' #' # Include `EOSDY` and `DCSREAS` variables below because they contain missing data. #' stopifnot( @@ -234,9 +231,7 @@ template_summary <- function(dataname, #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", adsl), -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")', -#' check = TRUE +#' cdisc_dataset("ADSL", adsl) #' ), #' modules = modules( #' tm_t_summary( diff --git a/R/tm_t_summary_by.R b/R/tm_t_summary_by.R index 75c845dd9c..6ea03afaf2 100644 --- a/R/tm_t_summary_by.R +++ b/R/tm_t_summary_by.R @@ -327,16 +327,13 @@ template_summary_by <- function(parentname, #' @export #' @examples #' # Preparation of the test case. -#' library(scda) -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adlb <- synthetic_cdisc_dataset("latest", "adlb") +#' adsl <- tmc_ex_adsl +#' adlb <- tmc_ex_adlb #' #' app <- init( #' data = cdisc_data( #' cdisc_dataset("ADSL", adsl), -#' cdisc_dataset("ADLB", adlb), -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADLB <- synthetic_cdisc_dataset("latest", "adlb")' # nolint +#' cdisc_dataset("ADLB", adlb) #' ), #' modules = modules( #' tm_t_summary_by( diff --git a/R/tm_t_tte.R b/R/tm_t_tte.R index 6974e3b6a5..f67677219d 100644 --- a/R/tm_t_tte.R +++ b/R/tm_t_tte.R @@ -380,9 +380,9 @@ template_tte <- function(dataname = "ANL", #' @export #' #' @examples -#' library(scda) -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +#' +#' ADSL <- tmc_ex_adsl +#' ADTTE <- tmc_ex_adtte #' #' arm_ref_comp <- list( #' ACTARMCD = list( @@ -397,12 +397,8 @@ template_tte <- function(dataname = "ANL", #' #' app <- init( #' data = cdisc_data( -#' cdisc_dataset("ADSL", ADSL, -#' code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' -#' ), -#' cdisc_dataset("ADTTE", ADTTE, -#' code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")' -#' ) +#' cdisc_dataset("ADSL", ADSL), +#' cdisc_dataset("ADTTE", ADTTE) #' ), #' modules = modules( #' tm_t_tte( diff --git a/R/utils.R b/R/utils.R index 3e9ac8a572..a2fe42a167 100644 --- a/R/utils.R +++ b/R/utils.R @@ -216,12 +216,13 @@ add_expr <- function(expr_ls, new_expr) { #' a single _bracketed_ expression. #' #' @export +#' #' @examples #' library(dplyr) -#' library(scda) #' library(tern) -#' adsl <- synthetic_cdisc_dataset("latest", "adsl") -#' adrs <- synthetic_cdisc_dataset("latest", "adrs") +#' +#' adsl <- tmc_ex_adsl +#' adrs <- tmc_ex_adrs #' #' expr1 <- substitute( #' expr = anl <- subset(df, PARAMCD == param), @@ -235,7 +236,7 @@ add_expr <- function(expr_ls, new_expr) { #' } #' ) #' -#' res <- teal.modules.clinical:::bracket_expr(list(expr1, expr2, expr3)) +#' res <- bracket_expr(list(expr1, expr2, expr3)) #' eval(res) #' table(anl$rsp_lab, anl$is_rsp) bracket_expr <- function(exprs) { diff --git a/R/validate_standard_inputs.R b/R/validate_standard_inputs.R index f8fda92b47..567948fb04 100644 --- a/R/validate_standard_inputs.R +++ b/R/validate_standard_inputs.R @@ -19,12 +19,10 @@ #' @keywords internal #' #' @examples -#' -#' -#' library(scda) #' library(shiny) -#' ADSL <- synthetic_cdisc_dataset("latest", "adsl") -#' ADAE <- synthetic_cdisc_dataset("latest", "adae") +#' +#' ADSL <- tmc_ex_adsl +#' ADAE <- tmc_ex_adae #' #' ui <- fluidPage( #' shiny::sliderInput("obs", "Max Age", diff --git a/_pkgdown.yml b/_pkgdown.yml index 77c86d5ef9..20a235bb64 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -48,3 +48,7 @@ reference: - split_col_expr - split_interactions - styled_expr + - title: Data + desc: Data included in the package. + contents: + - starts_with("ex_") diff --git a/data/tmc_ex_adae.rda b/data/tmc_ex_adae.rda new file mode 100644 index 0000000000..0a330fefa7 Binary files /dev/null and b/data/tmc_ex_adae.rda differ diff --git a/data/tmc_ex_adcm.rda b/data/tmc_ex_adcm.rda new file mode 100644 index 0000000000..98aaee5de0 Binary files /dev/null and b/data/tmc_ex_adcm.rda differ diff --git a/data/tmc_ex_adlb.rda b/data/tmc_ex_adlb.rda new file mode 100644 index 0000000000..a3f234a6aa Binary files /dev/null and b/data/tmc_ex_adlb.rda differ diff --git a/data/tmc_ex_adrs.rda b/data/tmc_ex_adrs.rda new file mode 100644 index 0000000000..cd45ba0d49 Binary files /dev/null and b/data/tmc_ex_adrs.rda differ diff --git a/data/tmc_ex_adsl.rda b/data/tmc_ex_adsl.rda new file mode 100644 index 0000000000..e331d6afb3 Binary files /dev/null and b/data/tmc_ex_adsl.rda differ diff --git a/data/tmc_ex_adtte.rda b/data/tmc_ex_adtte.rda new file mode 100644 index 0000000000..5260a4cac0 Binary files /dev/null and b/data/tmc_ex_adtte.rda differ diff --git a/inst/WORDLIST b/inst/WORDLIST index e793722786..7b55f82ace 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -4,6 +4,7 @@ ADLB ADMH ADRS ADSL +ADTTE ADVS ADaM AE @@ -24,6 +25,7 @@ NSE Newcombe PARAMCD Repo +Rua SREPs UI USUBJID @@ -36,6 +38,7 @@ cov coxph customizable datetime +de ggplot github grey diff --git a/man/bracket_expr.Rd b/man/bracket_expr.Rd index 64dad9c41b..5d47fcd6c3 100644 --- a/man/bracket_expr.Rd +++ b/man/bracket_expr.Rd @@ -15,10 +15,10 @@ Groups several expressions in a single \emph{bracketed} expression. } \examples{ library(dplyr) -library(scda) library(tern) -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adrs <- synthetic_cdisc_dataset("latest", "adrs") + +adsl <- tmc_ex_adsl +adrs <- tmc_ex_adrs expr1 <- substitute( expr = anl <- subset(df, PARAMCD == param), @@ -32,7 +32,7 @@ expr3 <- substitute( } ) -res <- teal.modules.clinical:::bracket_expr(list(expr1, expr2, expr3)) +res <- bracket_expr(list(expr1, expr2, expr3)) eval(res) table(anl$rsp_lab, anl$is_rsp) } diff --git a/man/ex_data.Rd b/man/ex_data.Rd new file mode 100644 index 0000000000..0cafb966f6 --- /dev/null +++ b/man/ex_data.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{ex_data} +\alias{ex_data} +\alias{tmc_ex_adsl} +\alias{tmc_ex_adae} +\alias{tmc_ex_adlb} +\alias{tmc_ex_adrs} +\alias{tmc_ex_adtte} +\alias{tmc_ex_adcm} +\title{Simulated CDISC Data for Examples} +\format{ +\code{rds} (\code{data.frame}) + +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 200 rows and 27 columns. + +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 541 rows and 53 columns. + +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4200 rows and 60 columns. + +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 1600 rows and 35 columns. + +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 1000 rows and 35 columns. + +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 1012 rows and 47 columns. +} +\usage{ +tmc_ex_adsl + +tmc_ex_adae + +tmc_ex_adlb + +tmc_ex_adrs + +tmc_ex_adtte + +tmc_ex_adcm +} +\description{ +Simulated CDISC Data for Examples +} +\section{Functions}{ +\itemize{ +\item \code{tmc_ex_adsl}: ADSL data + +\item \code{tmc_ex_adae}: ADAE data + +\item \code{tmc_ex_adlb}: ADLB data + +\item \code{tmc_ex_adrs}: ADRS data + +\item \code{tmc_ex_adtte}: ADTTE data + +\item \code{tmc_ex_adcm}: ADCM data + +}} +\keyword{datasets} diff --git a/man/template_binary_outcome.Rd b/man/template_binary_outcome.Rd index d916f05c87..7362691f40 100644 --- a/man/template_binary_outcome.Rd +++ b/man/template_binary_outcome.Rd @@ -77,11 +77,8 @@ Creates a valid expression for binary outcome analysis. \examples{ if (interactive()) { # Preparation of the test case. - library(dplyr) - library(scda) - library(tern) - adsl <- synthetic_cdisc_data("latest")$adsl - adrs <- synthetic_cdisc_data("latest")$adrs + adsl <- tmc_ex_adsl + adrs <- tmc_ex_adrs # Generate an expression for the analysis of responders. a <- template_binary_outcome( diff --git a/man/tm_a_gee.Rd b/man/tm_a_gee.Rd index 56818e36e4..d77d362669 100644 --- a/man/tm_a_gee.Rd +++ b/man/tm_a_gee.Rd @@ -106,9 +106,7 @@ ADQS <- synthetic_cdisc_dataset("latest", "adqs") \%>\% app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'synthetic_cdisc_dataset("latest", "adsl")' - ), + cdisc_dataset("ADSL", ADSL), cdisc_dataset("ADQS", ADQS, code = 'ADQS <- synthetic_cdisc_dataset("latest", "adqs") \%>\% dplyr::filter(ABLFL != "Y" & ABLFL2 != "Y") \%>\% diff --git a/man/tm_a_mmrm.Rd b/man/tm_a_mmrm.Rd index 7b02787b39..91e067d732 100644 --- a/man/tm_a_mmrm.Rd +++ b/man/tm_a_mmrm.Rd @@ -120,7 +120,6 @@ different convergence behavior. This is a known observation with the used packag numerical precision. } \examples{ - library(scda) ADSL <- synthetic_cdisc_dataset("latest", "adsl") diff --git a/man/tm_g_barchart_simple.Rd b/man/tm_g_barchart_simple.Rd index 2362d92f50..d6efcada08 100644 --- a/man/tm_g_barchart_simple.Rd +++ b/man/tm_g_barchart_simple.Rd @@ -64,11 +64,11 @@ it is ignored. } \examples{ library(dplyr) -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADAE <- synthetic_cdisc_dataset("latest", "adae") +ADSL <- tmc_ex_adsl \%>\% + dplyr::mutate(ITTFL = factor("Y")) +ADAE <- tmc_ex_adae adae_labels <- formatters::var_labels(ADAE, fill = FALSE) ADAE <- ADAE \%>\% dplyr::filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X"))) @@ -78,15 +78,8 @@ formatters::var_labels(ADAE) <- adae_labels app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), - cdisc_dataset("ADAE", ADAE, - code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae") - adae_labels <- formatters::var_labels(ADAE, fill = FALSE) - ADAE <- ADAE \%>\% - dplyr::filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X"))) - formatters::var_labels(ADAE) <- adae_labels - ADAE' - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADAE", ADAE) ), modules = modules( tm_g_barchart_simple( diff --git a/man/tm_g_ci.Rd b/man/tm_g_ci.Rd index 2d7b956686..6b215ea8af 100644 --- a/man/tm_g_ci.Rd +++ b/man/tm_g_ci.Rd @@ -65,18 +65,15 @@ For more details, see the help vignette: \code{vignette("custom-ggplot2-argument The module generates the R code and returns the corresponding output. } \examples{ - -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADLB <- synthetic_cdisc_dataset("latest", "adlb") + +ADSL <- tmc_ex_adsl +ADLB <- tmc_ex_adlb app <- init( data = cdisc_data( cdisc_dataset("ADSL", ADSL), - cdisc_dataset("ADLB", ADLB), - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") - ADLB <- synthetic_cdisc_dataset("latest", "adlb")' # nolint + cdisc_dataset("ADLB", ADLB) ), modules = modules( tm_g_ci( diff --git a/man/tm_g_forest_rsp.Rd b/man/tm_g_forest_rsp.Rd index 4a7b1e3157..2abfbc70eb 100644 --- a/man/tm_g_forest_rsp.Rd +++ b/man/tm_g_forest_rsp.Rd @@ -112,14 +112,12 @@ For more details, see the vignette: \code{vignette("custom-ggplot2-arguments", p This teal module produces a grid style Forest plot for response data with ADaM structure. } \examples{ - -library(scda) library(dplyr) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADRS <- synthetic_cdisc_dataset("latest", "adrs") \%>\% - mutate(AVALC = d_onco_rsp_label(AVALC)) \%>\% +ADSL <- tmc_ex_adsl +ADRS <- tmc_ex_adrs \%>\% + mutate(AVALC = tern::d_onco_rsp_label(AVALC)) \%>\% filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP") arm_ref_comp <- list( @@ -136,12 +134,7 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( cdisc_dataset("ADSL", ADSL), - cdisc_dataset("ADRS", ADRS), - code = - 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") - ADRS <- synthetic_cdisc_dataset("latest", "adrs") \%>\% - mutate(AVALC = d_onco_rsp_label(AVALC)) \%>\% - filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")' # nolint + cdisc_dataset("ADRS", ADRS) ), modules = modules( tm_g_forest_rsp( diff --git a/man/tm_g_forest_tte.Rd b/man/tm_g_forest_tte.Rd index ed18478997..2f1658661e 100644 --- a/man/tm_g_forest_tte.Rd +++ b/man/tm_g_forest_tte.Rd @@ -117,11 +117,10 @@ This teal module produces a grid style Forest plot for time-to-event data with ADaM structure } \examples{ -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +ADSL <- tmc_ex_adsl +ADTTE <- tmc_ex_adtte ADSL$RACE <- droplevels(ADSL$RACE) @@ -138,15 +137,8 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( - cdisc_dataset( - "ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") - ADSL$RACE <- droplevels(ADSL$RACE)' # nolint - ), - cdisc_dataset( - "ADTTE", ADTTE, - code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")' - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADTTE", ADTTE) ), modules = modules( tm_g_forest_tte( diff --git a/man/tm_g_ipp.Rd b/man/tm_g_ipp.Rd index ea2b239e4a..9ed790815b 100644 --- a/man/tm_g_ipp.Rd +++ b/man/tm_g_ipp.Rd @@ -107,11 +107,10 @@ ADaM structure. } \examples{ library(dplyr) -library(scda) library(nestcolor) -adsl <- synthetic_cdisc_dataset("latest", "adsl") \%>\% slice(1:20) -adlb <- synthetic_cdisc_dataset("latest", "adlb") +adsl <- tmc_ex_adsl \%>\% slice(1:20) +adlb <- tmc_ex_adlb adlb <- adlb \%>\% filter(USUBJID \%in\% adsl$USUBJID) adsl <- df_explicit_na(adsl) @@ -122,16 +121,11 @@ app <- init( data = cdisc_data( cdisc_dataset( "ADSL", - adsl, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") \%>\% slice(1:20) - ADSL <- df_explicit_na(ADSL)' # nolint + adsl ), cdisc_dataset( "ADLB", - adlb, - code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") - ADLB <- df_explicit_na(ADLB) \%>\% - dplyr::filter(AVISIT != "SCREENING")' # nolint + adlb ) ), modules = modules( diff --git a/man/tm_g_km.Rd b/man/tm_g_km.Rd index e4a05237f3..fdc98c35c9 100644 --- a/man/tm_g_km.Rd +++ b/man/tm_g_km.Rd @@ -102,11 +102,10 @@ This teal module produces a grid style Kaplan-Meier plot for data with ADaM structure. } \examples{ -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +ADSL <- tmc_ex_adsl +ADTTE <- tmc_ex_adtte arm_ref_comp <- list( ACTARMCD = list( @@ -121,8 +120,8 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), - cdisc_dataset("ADTTE", ADTTE, code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")') + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADTTE", ADTTE) ), modules = modules( tm_g_km( diff --git a/man/tm_g_lineplot.Rd b/man/tm_g_lineplot.Rd index 390ffff56b..2d614fce1c 100644 --- a/man/tm_g_lineplot.Rd +++ b/man/tm_g_lineplot.Rd @@ -123,23 +123,17 @@ This teal module produces a grid style Line Plot for data with ADaM structure. } \examples{ -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADLB <- synthetic_cdisc_dataset("latest", "adlb") +ADSL <- tmc_ex_adsl +ADLB <- tmc_ex_adlb ADLB <- dplyr::mutate(ADLB, AVISIT == forcats::fct_reorder(AVISIT, AVISITN, min)) app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADLB", ADLB, - code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") - ADLB <- dplyr::mutate(ADLB, AVISIT == forcats::fct_reorder(AVISIT, AVISITN, min))' # nolint - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADLB", ADLB) ), modules = modules( tm_g_lineplot( diff --git a/man/tm_g_pp_adverse_events.Rd b/man/tm_g_pp_adverse_events.Rd index 8224bc8d7c..c5801a3f0c 100644 --- a/man/tm_g_pp_adverse_events.Rd +++ b/man/tm_g_pp_adverse_events.Rd @@ -88,20 +88,15 @@ For more details, see the help vignette: \code{vignette("custom-ggplot2-argument This teal module produces a patient profile adverse events table and plot using ADaM datasets. } \examples{ -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADAE <- synthetic_cdisc_dataset("latest", "adae") +ADSL <- tmc_ex_adsl +ADAE <- tmc_ex_adae app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADAE", ADAE, - code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")' - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADAE", ADAE) ), modules = modules( tm_g_pp_adverse_events( diff --git a/man/tm_g_pp_patient_timeline.Rd b/man/tm_g_pp_patient_timeline.Rd index 5166a19a1f..6655489b23 100644 --- a/man/tm_g_pp_patient_timeline.Rd +++ b/man/tm_g_pp_patient_timeline.Rd @@ -102,14 +102,13 @@ For more details, see the help vignette: \code{vignette("custom-ggplot2-argument This teal module produces a patient profile timeline plot using ADaM datasets. } \examples{ -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADAE <- synthetic_cdisc_dataset("latest", "adae") -ADCM <- synthetic_cdisc_dataset("latest", "adcm") +ADSL <- tmc_ex_adsl +ADAE <- tmc_ex_adae +ADCM <- tmc_ex_adcm -#' Modify ADCM +# Modify ADCM ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) ADCM$CMDOSE <- 1 ADCM$CMDOSU <- "U" diff --git a/man/tm_g_pp_therapy.Rd b/man/tm_g_pp_therapy.Rd index 38cae4ed9a..bef9724dfb 100644 --- a/man/tm_g_pp_therapy.Rd +++ b/man/tm_g_pp_therapy.Rd @@ -100,13 +100,12 @@ For more details, see the help vignette: \code{vignette("custom-ggplot2-argument This teal module produces a patient profile therapy plot using ADaM datasets. } \examples{ -library(scda) library(nestcolor) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADCM <- synthetic_cdisc_dataset("latest", "adcm") +ADSL <- tmc_ex_adsl +ADCM <- tmc_ex_adcm -#' Modify ADCM +# Modify ADCM ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) ADCM$CMDOSE <- 1 ADCM$CMTRT <- ADCM$CMCAT @@ -127,26 +126,8 @@ adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), + cdisc_dataset("ADSL", ADSL), cdisc_dataset("ADCM", ADCM, - code = 'ADCM <- synthetic_cdisc_dataset("latest", "adcm") - ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) - ADCM$CMDOSE <- 1 - ADCM$CMTRT <- ADCM$CMCAT - ADCM$CMDOSU <- "U" - ADCM$CMROUTE <- "CMROUTE" - ADCM$CMDOSFRQ <- "CMDOSFRQ" - ADCM$CMASTDTM <- ADCM$ASTDTM - ADCM$CMAENDTM <- ADCM$AENDTM - formatters::var_labels( - ADCM[c("CMINDC", "CMTRT", "ASTDY", "AENDY")]) <- c( - "Indication", - "Reported Name of Drug, Med, or Therapy", - "Study Day of Start of Medication", - "Study Day of End of Medication") - ADCM', keys = adcm_keys ) ), diff --git a/man/tm_g_pp_vitals.Rd b/man/tm_g_pp_vitals.Rd index 85882e0760..d167049340 100644 --- a/man/tm_g_pp_vitals.Rd +++ b/man/tm_g_pp_vitals.Rd @@ -74,6 +74,7 @@ This teal module produces a patient profile vitals plot using ADaM datasets. \examples{ library(scda) library(nestcolor) + ADSL <- synthetic_cdisc_dataset("latest", "adsl") ADVS <- synthetic_cdisc_dataset("latest", "advs") diff --git a/man/tm_t_abnormality.Rd b/man/tm_t_abnormality.Rd index 212cf8b8ed..728769a0dc 100644 --- a/man/tm_t_abnormality.Rd +++ b/man/tm_t_abnormality.Rd @@ -105,35 +105,23 @@ Patients with the same abnormality at baseline as on the treatment visit can be excluded in accordance with GDSR specifications by using \code{exclude_base_abn}. } \examples{ -library(scda) library(dplyr) -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adlb <- synthetic_cdisc_dataset("latest", "adlb") \%>\% +adsl <- tmc_ex_adsl +adlb <- tmc_ex_adlb \%>\% mutate( ONTRTFL = case_when( AVISIT \%in\% c("SCREENING", "BASELINE") ~ "", TRUE ~ "Y" ) ) + attr(adlb[["ONTRTFL"]], "label") <- "On Treatment Record Flag" app <- init( data = cdisc_data( - cdisc_dataset("ADSL", adsl, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADLB", adlb, - code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") \%>\% - mutate( - ONTRTFL = case_when( - AVISIT \%in\% c("SCREENING", "BASELINE") ~ "", - TRUE ~ "Y" - ) - ) - attr(ADLB[["ONTRTFL"]], "label") <- "On Treatment Record Flag" - ADLB' - ) + cdisc_dataset("ADSL", adsl), + cdisc_dataset("ADLB", adlb) ), modules = modules( tm_t_abnormality( @@ -149,6 +137,10 @@ app <- init( selected = c("LBCAT", "PARAM"), keep_order = TRUE ), + baseline_var = teal.transform::choices_selected( + teal.transform::variable_choices(adlb, subset = "BNRIND"), + selected = "BNRIND", fixed = TRUE + ), grade = choices_selected( choices = variable_choices(adlb, subset = "ANRIND"), selected = "ANRIND", diff --git a/man/tm_t_abnormality_by_worst_grade.Rd b/man/tm_t_abnormality_by_worst_grade.Rd index 802de2bc1b..9bd1469b8a 100644 --- a/man/tm_t_abnormality_by_worst_grade.Rd +++ b/man/tm_t_abnormality_by_worst_grade.Rd @@ -95,22 +95,16 @@ For more details, see the vignette: \code{vignette("custom-basic-table-arguments Teal Module: Laboratory test results with highest grade post-baseline } \examples{ -library(scda) library(dplyr) -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adlb <- synthetic_cdisc_dataset("latest", "adlb") \%>\% +adsl <- tmc_ex_adsl +adlb <- tmc_ex_adlb \%>\% filter(!AVISIT \%in\% c("SCREENING", "BASELINE")) app <- init( data = cdisc_data( - cdisc_dataset("ADSL", adsl, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADLB", adlb, - code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb") \%>\% - filter(!AVISIT \%in\% c("SCREENING", "BASELINE"))' # nolint - ) + cdisc_dataset("ADSL", adsl), + cdisc_dataset("ADLB", adlb) ), modules = modules( tm_t_abnormality_by_worst_grade( diff --git a/man/tm_t_ancova.Rd b/man/tm_t_ancova.Rd index 46777a9b2f..85a06017be 100644 --- a/man/tm_t_ancova.Rd +++ b/man/tm_t_ancova.Rd @@ -109,10 +109,10 @@ to be meaningful. } } \examples{ - # Preparation of the test case. library(dplyr) library(scda) + adsl <- synthetic_cdisc_dataset("latest", "adsl") adqs <- synthetic_cdisc_dataset("latest", "adqs") diff --git a/man/tm_t_binary_outcome.Rd b/man/tm_t_binary_outcome.Rd index 6b54c107e6..eebb463b6c 100644 --- a/man/tm_t_binary_outcome.Rd +++ b/man/tm_t_binary_outcome.Rd @@ -121,10 +121,9 @@ reference group. } \examples{ library(dplyr) -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADRS <- synthetic_cdisc_dataset("latest", "adrs") \%>\% +ADSL <- tmc_ex_adsl +ADRS <- tmc_ex_adrs \%>\% mutate(AVALC = d_onco_rsp_label(AVALC)) \%>\% filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP") arm_ref_comp <- list( @@ -134,12 +133,7 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( cdisc_dataset("ADSL", ADSL), - cdisc_dataset("ADRS", ADRS), - code = - 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") - ADRS <- synthetic_cdisc_dataset("latest", "adrs") \%>\% - mutate(AVALC = d_onco_rsp_label(AVALC)) \%>\% - filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP")' # nolint + cdisc_dataset("ADRS", ADRS) ), modules = modules( tm_t_binary_outcome( diff --git a/man/tm_t_coxreg.Rd b/man/tm_t_coxreg.Rd index ddcfc8338a..f3293e3da4 100644 --- a/man/tm_t_coxreg.Rd +++ b/man/tm_t_coxreg.Rd @@ -133,10 +133,8 @@ Wald test will be substituted. ## The example below is based on the usual approach involving creation of ## a random CDISC dataset and then running the application. -library(scda) - -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADTTE <- synthetic_cdisc_dataset("latest", "adtte") +ADSL <- tmc_ex_adsl +ADTTE <- tmc_ex_adtte arm_ref_comp <- list( ACTARMCD = list( ref = "ARM B", @@ -150,12 +148,8 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADTTE", ADTTE, - code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")' - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADTTE", ADTTE) ), modules = modules( tm_t_coxreg( diff --git a/man/tm_t_events.Rd b/man/tm_t_events.Rd index 0b5f2484a1..f6f5ddbbf0 100644 --- a/man/tm_t_events.Rd +++ b/man/tm_t_events.Rd @@ -85,15 +85,14 @@ Teal Module: Events by Term } \examples{ library(dplyr) -library(scda) -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adae <- synthetic_cdisc_dataset("latest", "adae") +adsl <- tmc_ex_adsl +adae <- tmc_ex_adae app <- teal::init( data = cdisc_data( - cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), - cdisc_dataset("ADAE", adae, code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")') + cdisc_dataset("ADSL", adsl), + cdisc_dataset("ADAE", adae) ), modules = modules( tm_t_events( diff --git a/man/tm_t_events_by_grade.Rd b/man/tm_t_events_by_grade.Rd index 72cb185899..01f7924f05 100644 --- a/man/tm_t_events_by_grade.Rd +++ b/man/tm_t_events_by_grade.Rd @@ -86,16 +86,16 @@ Teal Module: Events by Grade } \examples{ library(dplyr) -library(scda) library(tern) -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adae <- synthetic_cdisc_dataset("latest", "adae") +adsl <- tmc_ex_adsl +adae <- tmc_ex_adae \%>\% + mutate_if(is.character, as.factor) # be certain of having factors app <- init( data = cdisc_data( - cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), - cdisc_dataset("ADAE", adae, code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")') + cdisc_dataset("ADSL", adsl), + cdisc_dataset("ADAE", adae) ), modules = modules( tm_t_events_by_grade( diff --git a/man/tm_t_events_summary.Rd b/man/tm_t_events_summary.Rd index 1515286915..ead8acb80a 100644 --- a/man/tm_t_events_summary.Rd +++ b/man/tm_t_events_summary.Rd @@ -107,9 +107,8 @@ Teal Module: Adverse Events Summary } \examples{ library(dplyr) -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") \%>\% +ADSL <- tmc_ex_adsl \%>\% mutate( DTHFL = case_when( # nolint !is.na(DTHDT) ~ "Y", @@ -118,7 +117,7 @@ ADSL <- synthetic_cdisc_dataset("latest", "adsl") \%>\% ) attr(ADSL[["DTHFL"]], "label") <- "Subject Death Flag" -ADAE <- synthetic_cdisc_dataset("latest", "adae") +ADAE <- tmc_ex_adae add_event_flags <- function(dat) { dat <- dat \%>\% @@ -150,45 +149,8 @@ aesi_vars <- names(ADAE)[startsWith(names(ADAE), "TMP_")] app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = - 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") \%>\% - mutate( - DTHFL = case_when( # nolint - !is.na(DTHDT) ~ "Y", - TRUE ~ "" - ) - ) - attr(ADSL[["DTHFL"]], "label") <- "Subject Death Flag" - ADSL' - ), - cdisc_dataset("ADAE", ADAE, - code = - 'ADAE <- synthetic_cdisc_dataset("latest", "adae") - add_event_flags <- function(dat) { - dat <- dat \%>\% - dplyr::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"]]) - ) - formatters::var_labels(dat)[names(column_labels)] <- as.character(column_labels) - dat - } - # Generating user-defined event flags. - ADAE <- ADAE \%>\% add_event_flags()' # nolint - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADAE", ADAE) ), modules = modules( tm_t_events_summary( diff --git a/man/tm_t_logistic.Rd b/man/tm_t_logistic.Rd index a752c21708..bc87580a3d 100644 --- a/man/tm_t_logistic.Rd +++ b/man/tm_t_logistic.Rd @@ -80,11 +80,10 @@ This module produces a multi-variable logistic regression table that matches the STREAM template \code{lgrt02}. } \examples{ -library(scda) library(dplyr) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADRS <- synthetic_cdisc_dataset("latest", "adrs") \%>\% +ADSL <- tmc_ex_adsl +ADRS <- tmc_ex_adrs \%>\% filter(PARAMCD \%in\% c("BESRSPI", "INVET")) arm_ref_comp <- list( @@ -100,13 +99,8 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADRS", ADRS, - code = 'ADRS <- synthetic_cdisc_dataset("latest", "adrs") \%>\% - filter(PARAMCD \%in\% c("BESRSPI", "INVET"))' # nolint - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADRS", ADRS) ), modules = modules( tm_t_logistic( diff --git a/man/tm_t_mult_events.Rd b/man/tm_t_mult_events.Rd index 5d7c806f05..75a8451434 100644 --- a/man/tm_t_mult_events.Rd +++ b/man/tm_t_mult_events.Rd @@ -77,17 +77,15 @@ Teal Module: Multiple Events by Term } \examples{ library(dplyr) -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADCM <- synthetic_cdisc_dataset("latest", "adcm") +ADSL <- tmc_ex_adsl +ADCM <- tmc_ex_adcm adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4") app <- teal::init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), + cdisc_dataset("ADSL", ADSL), cdisc_dataset("ADCM", ADCM, - code = 'ADCM <- synthetic_cdisc_dataset("latest", "adcm")', keys = adcm_keys ) ), diff --git a/man/tm_t_pp_basic_info.Rd b/man/tm_t_pp_basic_info.Rd index 2f7dfda86f..50a2d93c73 100644 --- a/man/tm_t_pp_basic_info.Rd +++ b/man/tm_t_pp_basic_info.Rd @@ -37,13 +37,11 @@ the \code{\link[shiny:helpText]{shiny::helpText()}} elements are useful.} This teal module produces a patient profile basic info report using ADaM datasets. } \examples{ -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") +ADSL <- tmc_ex_adsl app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")'), - check = TRUE + cdisc_dataset("ADSL", ADSL) ), modules = modules( tm_t_pp_basic_info( diff --git a/man/tm_t_pp_laboratory.Rd b/man/tm_t_pp_laboratory.Rd index 6e831807dc..860fffcfe0 100644 --- a/man/tm_t_pp_laboratory.Rd +++ b/man/tm_t_pp_laboratory.Rd @@ -61,18 +61,15 @@ the \code{\link[shiny:helpText]{shiny::helpText()}} elements are useful.} This teal module produces a patient profile laboratory table using ADaM datasets. } \examples{ -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADLB <- synthetic_cdisc_dataset("latest", "adlb") + +# Reduced data for tests +ADSL <- tmc_ex_adsl +ADLB <- tmc_ex_adlb app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADLB", ADLB, - code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb")' - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADLB", ADLB) ), modules = modules( tm_t_pp_laboratory( diff --git a/man/tm_t_pp_prior_medication.Rd b/man/tm_t_pp_prior_medication.Rd index 5cd53480d2..b5b327f221 100644 --- a/man/tm_t_pp_prior_medication.Rd +++ b/man/tm_t_pp_prior_medication.Rd @@ -53,11 +53,10 @@ the \code{\link[shiny:helpText]{shiny::helpText()}} elements are useful.} This teal module produces a patient prior medication report using ADaM datasets. } \examples{ -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADCM <- synthetic_cdisc_dataset("latest", "adcm") +ADSL <- tmc_ex_adsl +ADCM <- tmc_ex_adcm -#' Modify ADCM +# Modify ADCM ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) ADCM$CMDOSE <- 1 ADCM$CMTRT <- ADCM$CMCAT @@ -77,25 +76,8 @@ adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), + cdisc_dataset("ADSL", ADSL), cdisc_dataset("ADCM", ADCM, - code = 'ADCM <- synthetic_cdisc_dataset("latest", "adcm") - ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD)) - ADCM$CMDOSE <- 1 - ADCM$CMTRT <- ADCM$CMCAT - ADCM$CMDOSU <- "U" - ADCM$CMROUTE <- "CMROUTE" - ADCM$CMDOSFRQ <- "CMDOSFRQ" - ADCM$CMASTDTM <- ADCM$ASTDTM - ADCM$CMAENDTM <- ADCM$AENDTM - formatters::var_labels( - ADCM[c("CMINDC", "CMTRT", "ASTDY")]) <- c( - "Indication", - "Reported Name of Drug, Med, or Therapy", - "Study Day of Start of Medication" - )', keys = adcm_keys ) ), diff --git a/man/tm_t_shift_by_arm_by_worst.Rd b/man/tm_t_shift_by_arm_by_worst.Rd index 01bd8f957f..5e6a59002d 100644 --- a/man/tm_t_shift_by_arm_by_worst.Rd +++ b/man/tm_t_shift_by_arm_by_worst.Rd @@ -92,7 +92,6 @@ For more details, see the vignette: \code{vignette("custom-basic-table-arguments Teal Module: Shift by Arm by Worst } \examples{ - library(dplyr) library(tern) library(scda) diff --git a/man/tm_t_shift_by_grade.Rd b/man/tm_t_shift_by_grade.Rd index edacf41e40..7e535249e6 100644 --- a/man/tm_t_shift_by_grade.Rd +++ b/man/tm_t_shift_by_grade.Rd @@ -106,20 +106,13 @@ For more details, see the vignette: \code{vignette("custom-basic-table-arguments Teal Module: Grade Summary Table } \examples{ -library(scda) -library(dplyr) - -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adlb <- synthetic_cdisc_dataset("latest", "adlb") +adsl <- tmc_ex_adsl +adlb <- tmc_ex_adlb app <- init( data = cdisc_data( - cdisc_dataset("ADSL", adsl, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADLB", adlb, - code = 'ADLB <- synthetic_cdisc_dataset("latest", "adlb")' - ) + cdisc_dataset("ADSL", adsl), + cdisc_dataset("ADLB", adlb) ), modules = modules( tm_t_shift_by_grade( diff --git a/man/tm_t_smq.Rd b/man/tm_t_smq.Rd index 1615716a36..f6f2afa7d0 100644 --- a/man/tm_t_smq.Rd +++ b/man/tm_t_smq.Rd @@ -90,10 +90,8 @@ For more details, see the vignette: \code{vignette("custom-basic-table-arguments Adverse Events Table by Standardized \code{MedDRA} Query. } \examples{ -library(scda) - -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adae <- synthetic_cdisc_dataset("latest", "adae") +adsl <- tmc_ex_adsl +adae <- tmc_ex_adae names_baskets <- grep("^(SMQ|CQ).*NAM$", names(adae), value = TRUE) names_scopes <- grep("^SMQ.*SC$", names(adae), value = TRUE) @@ -111,12 +109,8 @@ cs_scopes <- choices_selected( app <- init( data = cdisc_data( - cdisc_dataset("ADSL", adsl, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADAE", adae, - code = 'ADAE <- synthetic_cdisc_dataset("latest", "adae")' - ) + cdisc_dataset("ADSL", adsl), + cdisc_dataset("ADAE", adae) ), modules = modules( tm_t_smq( diff --git a/man/tm_t_summary.Rd b/man/tm_t_summary.Rd index d48dd928fb..da2df26275 100644 --- a/man/tm_t_summary.Rd +++ b/man/tm_t_summary.Rd @@ -86,12 +86,9 @@ For more details, see the vignette: \code{vignette("custom-basic-table-arguments Teal Module: Summary of Variables } \examples{ -# Preparation of the test case. -library(dplyr) -library(scda) -library(tern) - -adsl <- synthetic_cdisc_dataset("latest", "adsl") +# Preparation of the test case +adsl <- tmc_ex_adsl +adsl$EOSDY[1] <- NA_integer_ # Include `EOSDY` and `DCSREAS` variables below because they contain missing data. stopifnot( @@ -101,9 +98,7 @@ stopifnot( app <- init( data = cdisc_data( - cdisc_dataset("ADSL", adsl), - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")', - check = TRUE + cdisc_dataset("ADSL", adsl) ), modules = modules( tm_t_summary( diff --git a/man/tm_t_summary_by.Rd b/man/tm_t_summary_by.Rd index a6a379aa63..3ffdccafcb 100644 --- a/man/tm_t_summary_by.Rd +++ b/man/tm_t_summary_by.Rd @@ -113,16 +113,13 @@ Teal Module: Summarize Variables by Row Groups Module } \examples{ # Preparation of the test case. -library(scda) -adsl <- synthetic_cdisc_dataset("latest", "adsl") -adlb <- synthetic_cdisc_dataset("latest", "adlb") +adsl <- tmc_ex_adsl +adlb <- tmc_ex_adlb app <- init( data = cdisc_data( cdisc_dataset("ADSL", adsl), - cdisc_dataset("ADLB", adlb), - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl") - ADLB <- synthetic_cdisc_dataset("latest", "adlb")' # nolint + cdisc_dataset("ADLB", adlb) ), modules = modules( tm_t_summary_by( diff --git a/man/tm_t_tte.Rd b/man/tm_t_tte.Rd index bf250071b7..3db9b345a6 100644 --- a/man/tm_t_tte.Rd +++ b/man/tm_t_tte.Rd @@ -124,9 +124,9 @@ filtering for \code{paramcd} one observation per patient is expected The arm and stratification variables and taken from the \code{parentname} data. } \examples{ -library(scda) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADTTE <- synthetic_cdisc_dataset("latest", "adtte") + +ADSL <- tmc_ex_adsl +ADTTE <- tmc_ex_adtte arm_ref_comp <- list( ACTARMCD = list( @@ -141,12 +141,8 @@ arm_ref_comp <- list( app <- init( data = cdisc_data( - cdisc_dataset("ADSL", ADSL, - code = 'ADSL <- synthetic_cdisc_dataset("latest", "adsl")' - ), - cdisc_dataset("ADTTE", ADTTE, - code = 'ADTTE <- synthetic_cdisc_dataset("latest", "adtte")' - ) + cdisc_dataset("ADSL", ADSL), + cdisc_dataset("ADTTE", ADTTE) ), modules = modules( tm_t_tte( diff --git a/man/validate_standard_inputs.Rd b/man/validate_standard_inputs.Rd index b081489065..c735c51bd4 100644 --- a/man/validate_standard_inputs.Rd +++ b/man/validate_standard_inputs.Rd @@ -48,12 +48,10 @@ Use \code{NULL} for no maximum.} \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} } \examples{ - - -library(scda) library(shiny) -ADSL <- synthetic_cdisc_dataset("latest", "adsl") -ADAE <- synthetic_cdisc_dataset("latest", "adae") + +ADSL <- tmc_ex_adsl +ADAE <- tmc_ex_adae ui <- fluidPage( shiny::sliderInput("obs", "Max Age", diff --git a/teal.modules.clinical.Rproj b/teal.modules.clinical.Rproj index 03a59a503f..ea83efd3cf 100644 --- a/teal.modules.clinical.Rproj +++ b/teal.modules.clinical.Rproj @@ -16,5 +16,6 @@ AutoAppendNewline: Yes StripTrailingWhitespace: Yes BuildType: Package +PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace diff --git a/vignettes/generate_tmc_test_data.Rmd b/vignettes/generate_tmc_test_data.Rmd new file mode 100644 index 0000000000..433254c9dc --- /dev/null +++ b/vignettes/generate_tmc_test_data.Rmd @@ -0,0 +1,1048 @@ +--- +title: "Example Data Generation" +date: "`r Sys.Date()`" +output: + rmarkdown::html_document: + theme: "spacelab" + highlight: "kate" + toc: true + toc_float: true +vignette: > + %\VignetteIndexEntry{Example Data Generation} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +editor_options: + markdown: + wrap: 72 +--- + +## Generating minimal data to test `teal.modules.clinical` + +The following script is used to create and save cached synthetic CDISC data to the `data/` directory to use in examples and tests in the `teal.modules.clinical` package. This script/vignette was initialized by Emily de la Rua in `tern`. + +_Disclaimer_: this vignette concerns mainly the development of minimal and stable test data and it is kept internal for feature traceability. + +## Setup & Helper Functions + +```{r setup, eval=FALSE} +library(dplyr) +library(formatters) + +study_duration_secs <- 31556952 * 2 + +sample_fct <- function(x, N, ...) { # nolint + checkmate::assert_number(N) + factor(sample(x, N, replace = TRUE, ...), levels = if (is.factor(x)) levels(x) else x) +} + +retain <- function(df, value_var, event, outside = NA) { + indices <- c(1, which(event == TRUE), nrow(df) + 1) + values <- c(outside, value_var[event == TRUE]) + rep(values, diff(indices)) +} + +relvar_init <- function(relvar1, relvar2) { + if (length(relvar1) != length(relvar2)) { + message(simpleError( + "The argument value length of relvar1 and relvar2 differ. They must contain the same number of elements." + )) + return(NA) + } + return(list("relvar1" = relvar1, "relvar2" = relvar2)) +} + +rel_var <- function(df = NULL, var_name = NULL, var_values = NULL, related_var = NULL) { + if (is.null(df)) { + message("Missing data frame argument value.") + return(NA) + } else { + n_relvar1 <- length(unique(df[, related_var, drop = TRUE])) + n_relvar2 <- length(var_values) + if (n_relvar1 != n_relvar2) { + message(paste("Unequal vector lengths for", related_var, "and", var_name)) + return(NA) + } else { + relvar1 <- unique(df[, related_var, drop = TRUE]) + relvar2_values <- rep(NA, nrow(df)) + for (r in seq_len(length(relvar1))) { + matched <- which(df[, related_var, drop = TRUE] == relvar1[r]) + relvar2_values[matched] <- var_values[r] + } + return(relvar2_values) + } + } +} + +visit_schedule <- function(visit_format = "WEEK", + n_assessments = 10L, + n_days = 5L) { + if (!(toupper(visit_format) %in% c("WEEK", "CYCLE"))) { + message("Visit format value must either be: WEEK or CYCLE") + return(NA) + } + if (toupper(visit_format) == "WEEK") { + assessments <- 1:n_assessments + assessments_ord <- -1:n_assessments + visit_values <- c("SCREENING", "BASELINE", paste(toupper(visit_format), assessments, "DAY", (assessments * 7) + 1)) + } else if (toupper(visit_format) == "CYCLE") { + cycles <- sort(rep(1:n_assessments, times = 1, each = n_days)) + days <- rep(seq(1:n_days), times = n_assessments, each = 1) + assessments_ord <- 0:(n_assessments * n_days) + visit_values <- c("SCREENING", paste(toupper(visit_format), cycles, "DAY", days)) + } + visit_values <- stats::reorder(factor(visit_values), assessments_ord) +} + +## ADSL + +generate_adsl <- function(N = 200) { # nolint + set.seed(1) + sys_dtm <- as.numeric(strptime("20/2/2019 11:16:16.683", "%d/%m/%Y %H:%M:%OS")) + country_site_prob <- c(.5, .121, .077, .077, .075, .052, .046, .025, .014, .003) + + tmc_ex_adsl <- tibble::tibble( + STUDYID = rep("AB12345", N), + COUNTRY = sample_fct( + c("CHN", "USA", "BRA", "PAK", "NGA", "RUS", "JPN", "GBR", "CAN", "CHE"), + N, + prob = country_site_prob + ), + SITEID = sample_fct(1:20, N, prob = rep(country_site_prob, times = 2)), + SUBJID = paste("id", seq_len(N), sep = "-"), + AGE = sapply(stats::rchisq(N, df = 5, ncp = 10), max, 0) + 20, + SEX = c("F", "M") %>% sample_fct(N, prob = c(.52, .48)), + ARMCD = c("ARM A", "ARM B", "ARM C") %>% sample_fct(N), + ARM = dplyr::recode( + .data$ARMCD, + "ARM A" = "A: Drug X", "ARM B" = "B: Placebo", "ARM C" = "C: Combination" + ), + ACTARMCD = .data$ARMCD, + ACTARM = .data$ARM, + RACE = c( + "ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE", "AMERICAN INDIAN OR ALASKA NATIVE", + "MULTIPLE", "NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER", "OTHER", "UNKNOWN" + ) %>% + sample_fct(N, prob = c(.55, .23, .16, .05, .004, .003, .002, .002)), + TRTSDTM = as.POSIXct( + sys_dtm + sample(seq(0, study_duration_secs), size = N, replace = TRUE), + origin = "1970-01-01" + ), + TRTEDTM = as.POSIXct(as.numeric(.data$TRTSDTM) + study_duration_secs, origin = "1970-01-01"), + EOSDY = as.numeric(ceiling(difftime(.data$TRTEDTM, .data$TRTSDTM, units = "days"))), + STRATA1 = c("A", "B", "C") %>% sample_fct(N), + STRATA2 = c("S1", "S2") %>% sample_fct(N), + BMRKR1 = stats::rchisq(N, 6), + BMRKR2 = sample_fct(c("LOW", "MEDIUM", "HIGH"), N) + ) + + # associate sites with countries and regions + tmc_ex_adsl <- tmc_ex_adsl %>% + dplyr::mutate( + SITEID = paste0(.data$COUNTRY, "-", .data$SITEID), + REGION1 = factor(dplyr::case_when( + COUNTRY %in% c("NGA") ~ "Africa", + COUNTRY %in% c("CHN", "JPN", "PAK") ~ "Asia", + COUNTRY %in% c("RUS") ~ "Eurasia", + COUNTRY %in% c("GBR") ~ "Europe", + COUNTRY %in% c("CAN", "USA") ~ "North America", + COUNTRY %in% c("BRA") ~ "South America", + TRUE ~ as.character(NA) + )), + SAFFL = factor("Y") + ) %>% + dplyr::mutate(USUBJID = paste(.data$STUDYID, .data$SITEID, .data$SUBJID, sep = "-")) + + # disposition related variables + # using probability of 1 for the "DEATH" level to ensure at least one death record exists + l_dcsreas <- list( + choices = c( + "ADVERSE EVENT", "DEATH", "LACK OF EFFICACY", "PHYSICIAN DECISION", + "PROTOCOL VIOLATION", "WITHDRAWAL BY PARENT/GUARDIAN", "WITHDRAWAL BY SUBJECT" + ), + prob = c(.2, 1, .1, .1, .2, .1, .1) + ) + l_dthcat_other <- list( + choices = c( + "Post-study reporting of death", "LOST TO FOLLOW UP", "MISSING", "SUICIDE", "UNKNOWN" + ), + prob = c(.1, .3, .3, .2, .1) + ) + + tmc_ex_adsl <- tmc_ex_adsl %>% + dplyr::mutate(EOSDT = as.Date(.data$TRTEDTM)) %>% + dplyr::mutate(EOSDY = as.numeric(ceiling(difftime(.data$TRTEDTM, .data$TRTSDTM, units = "days")))) %>% + dplyr::mutate(EOSSTT = dplyr::case_when( + EOSDY == max(EOSDY, na.rm = TRUE) ~ "COMPLETED", + EOSDY < max(EOSDY, na.rm = TRUE) ~ "DISCONTINUED", + is.na(TRTEDTM) ~ "ONGOING" + )) %>% + dplyr::mutate(EOTSTT = .data$EOSSTT) %>% + dplyr::mutate( + DCSREAS = ifelse( + .data$EOSSTT == "DISCONTINUED", + sample(x = l_dcsreas$choices, size = N, replace = TRUE, prob = l_dcsreas$prob), + as.character(NA) + ) + ) %>% + dplyr::mutate(study_duration_secs = study_duration_secs) + + tmc_ex_adsl <- tmc_ex_adsl %>% + dplyr::mutate(DTHDT = dplyr::case_when( + DCSREAS == "DEATH" ~ as.Date(.data$TRTEDTM) + sample(0:50, size = N, replace = TRUE) + )) + + # Adding labels + tmp_dt <- scda::synthetic_cdisc_dataset("latest", "adsl") + formatters::var_labels(tmc_ex_adsl) <- as.character(formatters::var_labels(tmp_dt)[names(tmc_ex_adsl)]) + rm(tmp_dt) + + save(tmc_ex_adsl, file = "data/tmc_ex_adsl.rda", compress = "xz") +} + +## ADAE + +generate_adae <- function(adsl = tmc_ex_adsl, + max_n_aes = 5) { + set.seed(1) + lookup_ae <- tibble::tribble( + ~AEBODSYS, ~AELLT, ~AEDECOD, ~AEHLT, ~AEHLGT, ~AETOXGR, ~AESOC, ~AESER, ~AEREL, + "cl A.1", "llt A.1.1.1.1", "dcd A.1.1.1.1", "hlt A.1.1.1", "hlgt A.1.1", "1", "cl A", "N", "N", + "cl A.1", "llt A.1.1.1.2", "dcd A.1.1.1.2", "hlt A.1.1.1", "hlgt A.1.1", "2", "cl A", "Y", "N", + "cl B.1", "llt B.1.1.1.1", "dcd B.1.1.1.1", "hlt B.1.1.1", "hlgt B.1.1", "5", "cl B", "Y", "Y", + "cl B.2", "llt B.2.1.2.1", "dcd B.2.1.2.1", "hlt B.2.1.2", "hlgt B.2.1", "3", "cl B", "N", "N", + "cl B.2", "llt B.2.2.3.1", "dcd B.2.2.3.1", "hlt B.2.2.3", "hlgt B.2.2", "1", "cl B", "Y", "N", + "cl C.1", "llt C.1.1.1.3", "dcd C.1.1.1.3", "hlt C.1.1.1", "hlgt C.1.1", "4", "cl C", "N", "Y", + "cl C.2", "llt C.2.1.2.1", "dcd C.2.1.2.1", "hlt C.2.1.2", "hlgt C.2.1", "2", "cl C", "N", "Y", + "cl D.1", "llt D.1.1.1.1", "dcd D.1.1.1.1", "hlt D.1.1.1", "hlgt D.1.1", "5", "cl D", "Y", "Y", + "cl D.1", "llt D.1.1.4.2", "dcd D.1.1.4.2", "hlt D.1.1.4", "hlgt D.1.1", "3", "cl D", "N", "N", + "cl D.2", "llt D.2.1.5.3", "dcd D.2.1.5.3", "hlt D.2.1.5", "hlgt D.2.1", "1", "cl D", "N", "Y" + ) + + aag <- utils::read.table( + sep = ",", header = TRUE, + text = paste( + "NAMVAR,SRCVAR,GRPTYPE,REFNAME,REFTERM,SCOPE", + "CQ01NAM,AEDECOD,CUSTOM,D.2.1.5.3/A.1.1.1.1 aesi,dcd D.2.1.5.3,", + "CQ01NAM,AEDECOD,CUSTOM,D.2.1.5.3/A.1.1.1.1 aesi,dcd A.1.1.1.1,", + "SMQ01NAM,AEDECOD,SMQ,C.1.1.1.3/B.2.2.3.1 aesi,dcd C.1.1.1.3,BROAD", + "SMQ01NAM,AEDECOD,SMQ,C.1.1.1.3/B.2.2.3.1 aesi,dcd B.2.2.3.1,BROAD", + "SMQ02NAM,AEDECOD,SMQ,Y.9.9.9.9/Z.9.9.9.9 aesi,dcd Y.9.9.9.9,NARROW", + "SMQ02NAM,AEDECOD,SMQ,Y.9.9.9.9/Z.9.9.9.9 aesi,dcd Z.9.9.9.9,NARROW", + sep = "\n" + ), stringsAsFactors = FALSE + ) + + adae <- Map( + function(id, sid) { + n_aes <- sample(c(0, seq_len(max_n_aes)), 1) + i <- sample(seq_len(nrow(lookup_ae)), n_aes, TRUE) + dplyr::mutate( + lookup_ae[i, ], + USUBJID = id, + STUDYID = sid + ) + }, + adsl$USUBJID, + adsl$STUDYID + ) %>% + Reduce(rbind, .) %>% + `[`(c(10, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9)) %>% + dplyr::mutate(AETERM = gsub("dcd", "trm", .data$AEDECOD)) %>% + dplyr::mutate(AESEV = dplyr::case_when( + AETOXGR == 1 ~ "MILD", + AETOXGR %in% c(2, 3) ~ "MODERATE", + AETOXGR %in% c(4, 5) ~ "SEVERE" + )) + + adae <- var_relabel( + adae, + STUDYID = "Study Identifier", + USUBJID = "Unique Subject Identifier" + ) + + # merge adsl to be able to add AE date and study day variables + adae <- dplyr::inner_join(adae, adsl, by = c("STUDYID", "USUBJID"), multiple = "all") %>% # nolint + dplyr::rowwise() %>% + dplyr::mutate(trtsdt_int = as.numeric(as.Date(.data$TRTSDTM))) %>% + dplyr::mutate(trtedt_int = dplyr::case_when( + !is.na(.data$TRTEDTM) ~ as.numeric(as.Date(.data$TRTEDTM)), + is.na(.data$TRTEDTM) ~ floor(trtsdt_int + (study_duration_secs) / 86400) + )) %>% + dplyr::mutate(ASTDTM = as.POSIXct( + (sample(.data$trtsdt_int:.data$trtedt_int, size = 1) * 86400), + origin = "1970-01-01" + )) %>% + dplyr::mutate(astdt_int = as.numeric(as.Date(.data$ASTDTM))) %>% + dplyr::mutate(ASTDY = ceiling(as.numeric(difftime(.data$ASTDTM, .data$TRTSDTM, units = "days")))) %>% + # add 1 to end of range incase both values passed to sample() are the same + dplyr::mutate(AENDTM = as.POSIXct( + (sample(.data$astdt_int:(.data$trtedt_int + 1), size = 1) * 86400), + origin = "1970-01-01" + )) %>% + dplyr::mutate(AENDY = ceiling(as.numeric(difftime(.data$AENDTM, .data$TRTSDTM, units = "days")))) %>% + dplyr::mutate(LDOSEDTM = as.POSIXct( + ifelse(.data$TRTSDTM < .data$ASTDTM, + lubridate::as_datetime(stats::runif(1, .data$TRTSDTM, .data$ASTDTM), tz = "EST"), + .data$ASTDTM + ), + origin = "1970-01-01" + )) %>% + dplyr::select(-"trtsdt_int", -"trtedt_int", -"astdt_int") %>% + dplyr::ungroup() %>% + dplyr::arrange(.data$STUDYID, .data$USUBJID, .data$ASTDTM, .data$AETERM) + + adae <- adae %>% + dplyr::group_by(.data$USUBJID) %>% + dplyr::mutate(AESEQ = seq_len(dplyr::n())) %>% + dplyr::mutate(ASEQ = .data$AESEQ) %>% + dplyr::ungroup() %>% + dplyr::arrange( + .data$STUDYID, + .data$USUBJID, + .data$ASTDTM, + .data$AETERM, + .data$AESEQ + ) + + outcomes <- c( + "UNKNOWN", + "NOT RECOVERED/NOT RESOLVED", + "RECOVERED/RESOLVED WITH SEQUELAE", + "RECOVERING/RESOLVING", + "RECOVERED/RESOLVED" + ) + + adae <- adae %>% + dplyr::mutate(AEOUT = factor(ifelse( + .data$AETOXGR == "5", + "FATAL", + as.character(sample_fct(outcomes, nrow(adae), prob = c(0.1, 0.2, 0.1, 0.3, 0.3))) + ))) %>% + dplyr::mutate(TRTEMFL = ifelse(.data$ASTDTM >= .data$TRTSDTM, "Y", "")) + + l_aag <- split(aag, interaction(aag$NAMVAR, aag$SRCVAR, aag$GRPTYPE, drop = TRUE)) + + # Create aesi flags + l_aesi <- lapply(l_aag, function(d_adag, d_adae) { + names(d_adag)[names(d_adag) == "REFTERM"] <- d_adag$SRCVAR[1] + names(d_adag)[names(d_adag) == "REFNAME"] <- d_adag$NAMVAR[1] + + if (d_adag$GRPTYPE[1] == "CUSTOM") { + d_adag <- d_adag[-which(names(d_adag) == "SCOPE")] + } else if (d_adag$GRPTYPE[1] == "SMQ") { + names(d_adag)[names(d_adag) == "SCOPE"] <- paste0(substr(d_adag$NAMVAR[1], 1, 5), "SC") + } + + d_adag <- d_adag[-which(names(d_adag) %in% c("NAMVAR", "SRCVAR", "GRPTYPE"))] + d_new <- dplyr::left_join(x = d_adae, y = d_adag, by = intersect(names(d_adae), names(d_adag))) + d_new[, dplyr::setdiff(names(d_new), names(d_adae)), drop = FALSE] + }, adae) + + tmc_ex_adae <- dplyr::bind_cols(adae, l_aesi) + + actions <- c( + "DOSE RATE REDUCED", + "UNKNOWN", + "NOT APPLICABLE", + "DRUG INTERRUPTED", + "DRUG WITHDRAWN", + "DOSE INCREASED", + "DOSE NOT CHANGED", + "DOSE REDUCED", + "NOT EVALUABLE" + ) + + tmc_ex_adae <- tmc_ex_adae %>% + dplyr::mutate(AEACN = factor(ifelse( + .data$AETOXGR == "5", + "NOT EVALUABLE", + as.character(sample_fct(actions, nrow(ADAE), prob = c(0.05, 0.05, 0.05, 0.01, 0.05, 0.1, 0.45, 0.1, 0.05))) + ))) + + # Adding labels + tmp_dt <- scda::synthetic_cdisc_dataset("latest", "adae") + formatters::var_labels(tmc_ex_adae) <- as.character(formatters::var_labels(tmp_dt)[names(tmc_ex_adae)]) + rm(tmp_dt) + + save(tmc_ex_adae, file = "data/tmc_ex_adae.rda", compress = "xz") +} + +## ADLB + +generate_adlb <- function(adsl = tmc_ex_adsl, + max_n_lbs = 5L) { + set.seed(1) + lbcat <- c("CHEMISTRY", "CHEMISTRY", "IMMUNOLOGY") + param <- c( + "Alanine Aminotransferase Measurement", + "C-Reactive Protein Measurement", + "Immunoglobulin A Measurement" + ) + paramcd <- c("ALT", "CRP", "IGA") + paramu <- c("U/L", "mg/L", "g/L") + aval_mean <- c(20, 1, 2) + visit_format <- "WEEK" + n_assessments <- 5L + n_days <- 5L + + # validate and initialize related variables + lbcat_init_list <- relvar_init(param, lbcat) + param_init_list <- relvar_init(param, paramcd) + unit_init_list <- relvar_init(param, paramu) + + adlb <- expand.grid( + STUDYID = unique(adsl$STUDYID), + USUBJID = adsl$USUBJID, + PARAM = as.factor(param_init_list$relvar1), + AVISIT = visit_schedule(visit_format = visit_format, n_assessments = n_assessments, n_days = n_days), + stringsAsFactors = FALSE + ) + + # assign AVAL based on different test + adlb <- adlb %>% + dplyr::mutate(AVAL = stats::rnorm(nrow(adlb), mean = 1, sd = 0.2)) %>% + dplyr::left_join(data.frame(PARAM = param, ADJUST = aval_mean), by = "PARAM") %>% + dplyr::mutate(AVAL = .data$AVAL * .data$ADJUST) %>% + dplyr::select(-"ADJUST") + + # assign related variable values: PARAMxLBCAT are related + adlb$LBCAT <- as.factor(rel_var( + df = adlb, + var_name = "LBCAT", + var_values = lbcat_init_list$relvar2, + related_var = "PARAM" + )) + + # assign related variable values: PARAMxPARAMCD are related + adlb$PARAMCD <- as.factor(rel_var( + df = adlb, + var_name = "PARAMCD", + var_values = param_init_list$relvar2, + related_var = "PARAM" + )) + + adlb$AVALU <- as.factor(rel_var( + df = adlb, + var_name = "AVALU", + var_values = unit_init_list$relvar2, + related_var = "PARAM" + )) + + adlb <- adlb %>% dplyr::mutate(AVISITN = dplyr::case_when( + AVISIT == "SCREENING" ~ -1, + AVISIT == "BASELINE" ~ 0, + (grepl("^WEEK", AVISIT) | grepl("^CYCLE", AVISIT)) ~ as.numeric(AVISIT) - 2, + TRUE ~ NA_real_ + )) + + adlb <- adlb %>% + dplyr::mutate(AVISITN = dplyr::case_when( + AVISIT == "SCREENING" ~ -1, + AVISIT == "BASELINE" ~ 0, + (grepl("^WEEK", AVISIT) | grepl("^CYCLE", AVISIT)) ~ as.numeric(AVISIT) - 2, + TRUE ~ NA_real_ + )) + + # order to prepare for change from screening and baseline values + adlb <- adlb[order(adlb$STUDYID, adlb$USUBJID, adlb$PARAMCD, adlb$AVISITN), ] + + adlb <- Reduce(rbind, lapply(split(adlb, adlb$USUBJID), function(x) { + x$STUDYID <- adsl$STUDYID[which(adsl$USUBJID == x$USUBJID[1])] + x$ABLFL2 <- ifelse(x$AVISIT == "SCREENING", "Y", "") + x$ABLFL <- ifelse(toupper(visit_format) == "WEEK" & x$AVISIT == "BASELINE", + "Y", + ifelse(toupper(visit_format) == "CYCLE" & x$AVISIT == "CYCLE 1 DAY 1", "Y", "") + ) + x + })) + + adlb$BASE <- ifelse(adlb$ABLFL2 != "Y", retain(adlb, adlb$AVAL, adlb$ABLFL == "Y"), NA) + + anrind_choices <- c("HIGH", "LOW", "NORMAL") + + adlb <- adlb %>% + dplyr::mutate(BASETYPE = "LAST") %>% + dplyr::mutate(ANRIND = sample_fct(anrind_choices, nrow(adlb), prob = c(0.1, 0.1, 0.8))) %>% + dplyr::mutate(ANRLO = dplyr::case_when( + .data$PARAMCD == "ALT" ~ 7, + .data$PARAMCD == "CRP" ~ 8, + .data$PARAMCD == "IGA" ~ 0.8 + )) %>% + dplyr::mutate(ANRHI = dplyr::case_when( + .data$PARAMCD == "ALT" ~ 55, + .data$PARAMCD == "CRP" ~ 10, + .data$PARAMCD == "IGA" ~ 3 + )) %>% + dplyr::mutate(DTYPE = NA) %>% + dplyr::mutate(ATOXGR = factor(dplyr::case_when( + .data$ANRIND == "LOW" ~ sample( + c("-1", "-2", "-3", "-4", "-5"), + nrow(adlb), + replace = TRUE, + prob = c(0.30, 0.25, 0.20, 0.15, 0) + ), + .data$ANRIND == "HIGH" ~ sample( + c("1", "2", "3", "4", "5"), + nrow(adlb), + replace = TRUE, + prob = c(0.30, 0.25, 0.20, 0.15, 0) + ), + .data$ANRIND == "NORMAL" ~ "0" + ))) %>% + dplyr::group_by(.data$USUBJID, .data$PARAMCD, .data$BASETYPE) %>% + dplyr::mutate(BTOXGR = .data$ATOXGR[.data$ABLFL == "Y"]) %>% + dplyr::ungroup() + + # High and low descriptions of the different PARAMCD values + # This is currently hard coded as the GDSR does not have these descriptions yet + grade_lookup <- tibble::tribble( + ~PARAMCD, ~ATOXDSCL, ~ATOXDSCH, + "ALB", "Hypoalbuminemia", NA_character_, + "ALKPH", NA_character_, "Alkaline phosphatase increased", + "ALT", NA_character_, "Alanine aminotransferase increased", + "AST", NA_character_, "Aspartate aminotransferase increased", + "BILI", NA_character_, "Blood bilirubin increased", + "CA", "Hypocalcemia", "Hypercalcemia", + "CHOLES", NA_character_, "Cholesterol high", + "CK", NA_character_, "CPK increased", + "CREAT", NA_character_, "Creatinine increased", + "CRP", NA_character_, "C reactive protein increased", + "GGT", NA_character_, "GGT increased", + "GLUC", "Hypoglycemia", "Hyperglycemia", + "HGB", "Anemia", "Hemoglobin increased", + "IGA", NA_character_, "Immunoglobulin A increased", + "POTAS", "Hypokalemia", "Hyperkalemia", + "LYMPH", "CD4 lymphocytes decreased", NA_character_, + "PHOS", "Hypophosphatemia", NA_character_, + "PLAT", "Platelet count decreased", NA_character_, + "SODIUM", "Hyponatremia", "Hypernatremia", + "WBC", "White blood cell decreased", "Leukocytosis", + ) + + # merge grade_lookup onto adlb + adlb <- dplyr::left_join(adlb, grade_lookup, by = "PARAMCD") + + adlb <- var_relabel( + adlb, + STUDYID = "Study Identifier", + USUBJID = "Unique Subject Identifier" + ) + + # merge adsl to be able to add LB date and study day variables + adlb <- dplyr::inner_join( + adsl, + adlb, + by = c("STUDYID", "USUBJID"), + multiple = "all" + ) %>% + dplyr::rowwise() %>% + dplyr::mutate(trtsdt_int = as.numeric(as.Date(.data$TRTSDTM))) %>% + dplyr::mutate(trtedt_int = dplyr::case_when( + !is.na(TRTEDTM) ~ as.numeric(as.Date(.data$TRTEDTM)), + is.na(TRTEDTM) ~ floor(.data$trtsdt_int + study_duration_secs / 86400) + )) %>% + dplyr::mutate(ADTM = as.POSIXct( + (sample(.data$trtsdt_int:.data$trtedt_int, size = 1) * 86400), + origin = "1970-01-01" + )) %>% + dplyr::select(-"trtsdt_int", -"trtedt_int") %>% + dplyr::ungroup() %>% + dplyr::arrange(.data$STUDYID, .data$USUBJID, .data$ADTM) + + adlb <- adlb %>% + dplyr::mutate(ASPID = sample(seq_len(dplyr::n()))) %>% + dplyr::group_by(.data$USUBJID) %>% + dplyr::mutate(LBSEQ = seq_len(dplyr::n())) %>% + dplyr::ungroup() %>% + dplyr::arrange( + .data$STUDYID, + .data$USUBJID, + .data$PARAMCD, + .data$BASETYPE, + .data$AVISITN, + .data$DTYPE, + .data$ADTM, + .data$LBSEQ, + .data$ASPID + ) + + adlb <- adlb %>% dplyr::mutate(ONTRTFL = factor(dplyr::case_when( + is.na(.data$TRTSDTM) ~ "", + is.na(.data$ADTM) ~ "Y", + (.data$ADTM < .data$TRTSDTM) ~ "", + (.data$ADTM > .data$TRTEDTM) ~ "", + TRUE ~ "Y" + ))) + + flag_variables <- function(data, + apply_grouping, + apply_filter, + apply_mutate) { + data_compare <- data %>% + dplyr::mutate(row_check = seq_len(nrow(data))) + + data <- data_compare %>% + { + if (apply_grouping == TRUE) { + dplyr::group_by(., .data$USUBJID, .data$PARAMCD, .data$BASETYPE, .data$AVISIT) + } else { + dplyr::group_by(., .data$USUBJID, .data$PARAMCD, .data$BASETYPE) + } + } %>% + dplyr::arrange(.data$ADTM, .data$ASPID, .data$LBSEQ) %>% + { + if (apply_filter == TRUE) { + dplyr::filter( + ., + (.data$AVISIT != "BASELINE" & .data$AVISIT != "SCREENING") & + (.data$ONTRTFL == "Y" | .data$ADTM <= .data$TRTSDTM) + ) %>% + dplyr::filter(.data$ATOXGR == max(as.numeric(as.character(.data$ATOXGR)))) + } else if (apply_filter == FALSE) { + dplyr::filter( + ., + (.data$AVISIT != "BASELINE" & .data$AVISIT != "SCREENING") & + (.data$ONTRTFL == "Y" | .data$ADTM <= .data$TRTSDTM) + ) %>% + dplyr::filter(.data$ATOXGR == min(as.numeric(as.character(.data$ATOXGR)))) + } else { + dplyr::filter( + ., + .data$AVAL == min(.data$AVAL) & + (.data$AVISIT != "BASELINE" & .data$AVISIT != "SCREENING") & + (.data$ONTRTFL == "Y" | .data$ADTM <= .data$TRTSDTM) + ) + } + } %>% + dplyr::slice(1) %>% + { + if (apply_mutate == TRUE) { + dplyr::mutate(., new_var = ifelse(is.na(.data$DTYPE), "Y", "")) + } else { + dplyr::mutate(., new_var = ifelse(is.na(.data$AVAL) == FALSE & is.na(.data$DTYPE), "Y", "")) + } + } %>% + dplyr::ungroup() + + data_compare$new_var <- ifelse(data_compare$row_check %in% data$row_check, "Y", "") + + data_compare <- data_compare[, -which(names(data_compare) %in% c("row_check"))] + + return(data_compare) + } + + adlb <- flag_variables(adlb, TRUE, "ELSE", FALSE) %>% dplyr::rename(WORS01FL = "new_var") + adlb <- flag_variables(adlb, FALSE, TRUE, TRUE) %>% dplyr::rename(WGRHIFL = "new_var") + adlb <- flag_variables(adlb, FALSE, FALSE, TRUE) %>% dplyr::rename(WGRLOFL = "new_var") + adlb <- flag_variables(adlb, TRUE, TRUE, TRUE) %>% dplyr::rename(WGRHIVFL = "new_var") + adlb <- flag_variables(adlb, TRUE, FALSE, TRUE) %>% dplyr::rename(WGRLOVFL = "new_var") + + tmc_ex_adlb <- adlb %>% dplyr::mutate( + ANL01FL = ifelse( + (.data$ABLFL == "Y" | (.data$WORS01FL == "Y" & is.na(.data$DTYPE))) & + (.data$AVISIT != "SCREENING"), + "Y", + "" + ), + PARAM = as.factor(.data$PARAM) + ) + + # BNRIND column + tmc_ex_adlb <- tmc_ex_adlb %>% + group_by(.data$USUBJID, .data$PARAMCD, .data$BASETYPE) %>% + mutate(BNRIND = .data$ANRIND[.data$ABLFL == "Y"]) %>% + ungroup() + + # ADY column + tmc_ex_adlb <- tmc_ex_adlb %>% + dplyr::mutate(ADY = ceiling(as.numeric(difftime(.data$ADTM, .data$TRTSDTM, units = "days")))) + + # PARAMCD should be factor + tmc_ex_adlb$PARAMCD <- as.factor(tmc_ex_adlb$PARAMCD) + + # CHG and PCHG columns + tmc_ex_adlb <- tmc_ex_adlb %>% + dplyr::mutate(CHG = .data$AVAL - .data$BASE) %>% + dplyr::mutate(PCHG = 100 * (.data$CHG / .data$BASE)) + + # Adding labels + tmp_dt <- scda::synthetic_cdisc_dataset("latest", "adlb") + formatters::var_labels(tmc_ex_adlb) <- as.character(formatters::var_labels(tmp_dt)[names(tmc_ex_adlb)]) + rm(tmp_dt) + + save(tmc_ex_adlb, file = "data/tmc_ex_adlb.rda", compress = "xz") +} + +## ADRS + +generate_adrs <- function(adsl = tmc_ex_adsl) { + set.seed(1) + param_codes <- stats::setNames(1:5, c("CR", "PR", "SD", "PD", "NE")) + + lookup_ars <- expand.grid( + ARM = c("A: Drug X", "B: Placebo", "C: Combination"), + AVALC = names(param_codes) + ) %>% dplyr::mutate( + AVAL = param_codes[.data$AVALC], + p_scr = c(rep(0, 3), rep(0, 3), c(1, 1, 1), c(0, 0, 0), c(0, 0, 0)), + p_bsl = c(rep(0, 3), rep(0, 3), c(1, 1, 1), c(0, 0, 0), c(0, 0, 0)), + p_cycle = c(c(.4, .3, .5), c(.35, .25, .25), c(.1, .2, .08), c(.14, 0.15, 0.15), c(.01, 0.1, 0.02)), + p_eoi = c(c(.4, .3, .5), c(.35, .25, .25), c(.1, .2, .08), c(.14, 0.15, 0.15), c(.01, 0.1, 0.02)), + p_fu = c(c(.3, .2, .4), c(.2, .1, .3), c(.2, .2, .2), c(.3, .5, 0.1), rep(0, 3)) + ) + + adrs <- split(adsl, adsl$USUBJID) %>% + lapply(function(pinfo) { + probs <- dplyr::filter(lookup_ars, .data$ARM == as.character(pinfo$ACTARM)) + + # screening + rsp_screen <- sample(probs$AVALC, 1, prob = probs$p_scr) %>% as.character() + # baseline + rsp_bsl <- sample(probs$AVALC, 1, prob = probs$p_bsl) %>% as.character() + # cycle + rsp_c2d1 <- sample(probs$AVALC, 1, prob = probs$p_cycle) %>% as.character() + rsp_c4d1 <- sample(probs$AVALC, 1, prob = probs$p_cycle) %>% as.character() + # end of induction + rsp_eoi <- sample(probs$AVALC, 1, prob = probs$p_eoi) %>% as.character() + # follow up + rsp_fu <- sample(probs$AVALC, 1, prob = probs$p_fu) %>% as.character() + + best_rsp <- min(param_codes[c(rsp_screen, rsp_bsl, rsp_eoi, rsp_fu, rsp_c2d1, rsp_c4d1)]) + best_rsp_i <- which.min(param_codes[c(rsp_screen, rsp_bsl, rsp_eoi, rsp_fu, rsp_c2d1, rsp_c4d1)]) + + avisit <- c("SCREENING", "BASELINE", "CYCLE 2 DAY 1", "CYCLE 4 DAY 1", "END OF INDUCTION", "FOLLOW UP") + + # meaningful date information + trtsdt_int <- as.numeric(as.Date(pinfo$TRTSDTM)) + trtedt_int <- ifelse( + !is.na(pinfo$TRTEDTM), as.numeric(as.Date(pinfo$TRTEDTM)), + floor(trtsdt_int + (pinfo$study_duration_secs) / 86400) + ) + scr_date <- as.POSIXct(((trtsdt_int - 100) * 86400), origin = "1970-01-01") + bs_date <- pinfo$TRTSDTM + flu_date <- as.POSIXct((sample(trtsdt_int:trtedt_int, size = 1) * 86400), origin = "1970-01-01") + eoi_date <- as.POSIXct((sample(trtsdt_int:trtedt_int, size = 1) * 86400), origin = "1970-01-01") + c2d1_date <- as.POSIXct((sample(trtsdt_int:trtedt_int, size = 1) * 86400), origin = "1970-01-01") + c4d1_date <- min(c2d1_date + 60 * 86400, pinfo$TRTEDTM) + + tibble::tibble( + STUDYID = pinfo$STUDYID, + USUBJID = pinfo$USUBJID, + PARAMCD = as.factor(c(rep("OVRINV", 6), "BESRSPI", "INVET")), + PARAM = as.factor(dplyr::recode( + .data$PARAMCD, + OVRINV = "Overall Response by Investigator - by visit", + OVRSPI = "Best Overall Response by Investigator (no confirmation required)", + BESRSPI = "Best Confirmed Overall Response by Investigator", + INVET = "Investigator End Of Induction Response" + )), + AVALC = c( + rsp_screen, rsp_bsl, rsp_c2d1, rsp_c4d1, rsp_eoi, rsp_fu, + names(param_codes)[best_rsp], + rsp_eoi + ), + AVAL = param_codes[.data$AVALC], + AVISIT = factor(c(avisit, avisit[best_rsp_i], avisit[5]), levels = avisit) + ) %>% + merge( + tibble::tibble( + AVISIT = avisit, + ADTM = c(scr_date, bs_date, c2d1_date, c4d1_date, eoi_date, flu_date), + AVISITN = c(-1, 0, 2, 4, 999, 999), + TRTSDTM = pinfo$TRTSDTM + ) %>% + dplyr::select(-"TRTSDTM"), + by = "AVISIT" + ) + }) %>% + Reduce(rbind, .) %>% + dplyr::mutate( + AVALC = factor(.data$AVALC, levels = names(param_codes)), + DTHFL = factor(sample(c("Y", "N"), nrow(.), replace = TRUE, prob = c(1, 0.8))) + ) + + adrs <- var_relabel( + adrs, + STUDYID = "Study Identifier", + USUBJID = "Unique Subject Identifier" + ) + + # merge ADSL to be able to add RS date and study day variables + adrs <- dplyr::inner_join( + adsl, + adrs, + by = c("STUDYID", "USUBJID"), + multiple = "all" + ) + + tmc_ex_adrs <- adrs %>% + dplyr::arrange( + .data$STUDYID, + .data$USUBJID, + .data$PARAMCD, + .data$AVISITN, + .data$ADTM + ) + + # Adding labels + tmp_dt <- scda::synthetic_cdisc_dataset("latest", "adrs") + formatters::var_labels(tmc_ex_adrs) <- as.character(formatters::var_labels(tmp_dt)[names(tmc_ex_adrs)]) + rm(tmp_dt) + + save(tmc_ex_adrs, file = "data/tmc_ex_adrs.rda", compress = "xz") +} + +## ADTTE + +generate_adtte <- function(adsl = tmc_ex_adsl) { + set.seed(1) + lookup_tte <- tibble::tribble( + ~ARM, ~PARAMCD, ~PARAM, ~LAMBDA, ~CNSR_P, + "ARM A", "OS", "Overall Survival", log(2) / 610, 0.4, + "ARM B", "OS", "Overall Survival", log(2) / 490, 0.3, + "ARM C", "OS", "Overall Survival", log(2) / 365, 0.2, + "ARM A", "PFS", "Progression Free Survival", log(2) / 365, 0.4, + "ARM B", "PFS", "Progression Free Survival", log(2) / 305, 0.3, + "ARM C", "PFS", "Progression Free Survival", log(2) / 243, 0.2, + "ARM A", "EFS", "Event Free Survival", log(2) / 365, 0.4, + "ARM B", "EFS", "Event Free Survival", log(2) / 305, 0.3, + "ARM C", "EFS", "Event Free Survival", log(2) / 243, 0.2, + "ARM A", "CRSD", "Duration of Confirmed Response", log(2) / 305, 0.4, + "ARM B", "CRSD", "Duration of Confirmed Response", log(2) / 243, 0.3, + "ARM C", "CRSD", "Duration of Confirmed Response", log(2) / 182, 0.2 + ) + + evntdescr_sel <- c( + "Death", + "Disease Progression", + "Last Tumor Assessment", + "Adverse Event", + "Last Date Known To Be Alive" + ) + + cnsdtdscr_sel <- c( + "Preferred Term", + "Clinical Cut Off", + "Completion or Discontinuation", + "End of AE Reporting Period" + ) + + adtte <- split(adsl, adsl$USUBJID) %>% + lapply(FUN = function(pinfo) { + lookup_tte %>% + dplyr::filter(.data$ARM == as.character(pinfo$ACTARMCD)) %>% + dplyr::rowwise() %>% + dplyr::mutate( + STUDYID = pinfo$STUDYID, + USUBJID = pinfo$USUBJID, + CNSR = sample(c(0, 1), 1, prob = c(1 - .data$CNSR_P, .data$CNSR_P)), + AVAL = stats::rexp(1, .data$LAMBDA), + AVALU = "DAYS", + EVNTDESC = if (.data$CNSR == 1) { + sample(evntdescr_sel[-c(1:2)], 1) + } else { + ifelse(.data$PARAMCD == "OS", + sample(evntdescr_sel[1], 1), + sample(evntdescr_sel[c(1:2)], 1) + ) + } + ) %>% + dplyr::select(-"LAMBDA", -"CNSR_P") + }) %>% + Reduce(rbind, .) + + adtte <- var_relabel( + adtte, + STUDYID = "Study Identifier", + USUBJID = "Unique Subject Identifier" + ) + + # merge ADSL to be able to add TTE date and study day variables + adtte <- dplyr::inner_join( + adsl, + dplyr::select(adtte, -"ARM"), + by = c("STUDYID", "USUBJID"), + multiple = "all" + ) %>% + dplyr::rowwise() %>% + dplyr::mutate(trtsdt_int = as.numeric(as.Date(.data$TRTSDTM))) %>% + dplyr::mutate(trtedt_int = dplyr::case_when( + !is.na(TRTEDTM) ~ as.numeric(as.Date(TRTEDTM)), + is.na(TRTEDTM) ~ floor(trtsdt_int + (study_duration_secs) / 86400) + )) %>% + dplyr::mutate(ADTM = as.POSIXct( + (sample(.data$trtsdt_int:.data$trtedt_int, size = 1) * 86400), + origin = "1970-01-01" + )) %>% + dplyr::select(-"trtsdt_int", -"trtedt_int") %>% + dplyr::ungroup() %>% + dplyr::arrange(.data$STUDYID, .data$USUBJID, .data$ADTM) + + adtte <- adtte %>% + dplyr::group_by(.data$USUBJID) %>% + dplyr::mutate(PARAM = as.factor(.data$PARAM)) %>% + dplyr::mutate(PARAMCD = as.factor(.data$PARAMCD)) %>% + dplyr::ungroup() %>% + dplyr::arrange( + .data$STUDYID, + .data$USUBJID, + .data$PARAMCD, + .data$ADTM + ) + + # adding adverse event counts and log follow-up time + tmc_ex_adtte <- dplyr::bind_rows( + adtte, + data.frame(adtte %>% + dplyr::group_by(.data$USUBJID) %>% + dplyr::slice_head(n = 1) %>% + dplyr::mutate( + PARAMCD = "TNE", + PARAM = "Total Number of Exacerbations", + AVAL = stats::rpois(1, 3), + AVALU = "COUNT", + lgTMATRSK = log(stats::rexp(1, rate = 3)), + dplyr::across(c("ADTM", "EVNTDESC"), ~NA) + )) + ) %>% + dplyr::arrange( + .data$STUDYID, + .data$USUBJID, + .data$PARAMCD, + .data$ADTM + ) + + # Adding labels + tmp_dt <- scda::synthetic_cdisc_dataset("latest", "adtte") + formatters::var_labels(tmc_ex_adtte) <- as.character(formatters::var_labels(tmp_dt)[names(tmc_ex_adtte)]) + rm(tmp_dt) + + save(tmc_ex_adtte, file = "data/tmc_ex_adtte.rda", compress = "xz") +} + +## ADCM + +generate_adcm <- function(adsl = tmc_ex_adsl) { + set.seed(1) + max_n_cms <- 10L + + lookup_cm <- tibble::tribble( + ~CMCLAS, ~CMDECOD, ~ATIREL, + "medcl A", "medname A_1/3", "PRIOR", + "medcl A", "medname A_2/3", "CONCOMITANT", + "medcl A", "medname A_3/3", "CONCOMITANT", + "medcl B", "medname B_1/4", "CONCOMITANT", + "medcl B", "medname B_2/4", "PRIOR", + "medcl B", "medname B_3/4", "PRIOR", + "medcl B", "medname B_4/4", "CONCOMITANT", + "medcl C", "medname C_1/2", "CONCOMITANT", + "medcl C", "medname C_2/2", "CONCOMITANT" + ) + + adcm <- Map(function(id, sid) { # nolint + n_cms <- sample(c(0, seq_len(max_n_cms)), 1) + i <- sample(seq_len(nrow(lookup_cm)), n_cms, TRUE) + dplyr::mutate( + lookup_cm[i, ], + USUBJID = id, + STUDYID = sid + ) + }, adsl$USUBJID, adsl$STUDYID) %>% + Reduce(rbind, .) %>% + `[`(c(4, 5, 1, 2, 3)) %>% + dplyr::mutate(CMCAT = .data$CMCLAS) + + adcm <- var_relabel( # nolint + adcm, + STUDYID = "Study Identifier", + USUBJID = "Unique Subject Identifier" + ) + + # merge adsl to be able to add CM date and study day variables + adcm <- dplyr::inner_join( # nolint + adcm, + adsl, + by = c("STUDYID", "USUBJID"), + multiple = "all" + ) %>% + dplyr::rowwise() %>% + dplyr::mutate(trtsdt_int = as.numeric(as.Date(.data$TRTSDTM))) %>% + dplyr::mutate(trtedt_int = dplyr::case_when( + !is.na(TRTEDTM) ~ as.numeric(as.Date(.data$TRTEDTM)), + is.na(TRTEDTM) ~ floor(.data$trtsdt_int + (.data$study_duration_secs) / 86400) + )) %>% + dplyr::mutate(ASTDTM = as.POSIXct( + (sample(.data$trtsdt_int:.data$trtedt_int, size = 1) * 86400), + origin = "1970-01-01" + )) %>% + dplyr::mutate(astdt_int = as.numeric(as.Date(.data$ASTDTM))) %>% + dplyr::mutate(ASTDY = ceiling(as.numeric(difftime(.data$ASTDTM, .data$TRTSDTM, units = "days")))) %>% + # add 1 to end of range incase both values passed to sample() are the same + dplyr::mutate(AENDTM = as.POSIXct( + ( + sample(.data$astdt_int:(.data$trtedt_int + 1), size = 1) * 86400), + origin = "1970-01-01" + )) %>% + dplyr::mutate(AENDY = ceiling(as.numeric(difftime(.data$AENDTM, .data$TRTSDTM, units = "days")))) %>% + dplyr::select(-"trtsdt_int", -"trtedt_int", -"astdt_int") %>% + dplyr::ungroup() %>% + dplyr::arrange(.data$STUDYID, .data$USUBJID, .data$ASTDTM) + + tmc_ex_adcm <- adcm %>% # nolint + dplyr::group_by(.data$USUBJID) %>% + dplyr::mutate(CMSEQ = seq_len(dplyr::n())) %>% + dplyr::mutate(ASEQ = .data$CMSEQ) %>% + dplyr::ungroup() %>% + dplyr::arrange(.data$STUDYID, .data$USUBJID, .data$ASTDTM, .data$CMSEQ) %>% + dplyr::mutate( + ATC1 = paste("ATCCLAS1", substr(.data$CMDECOD, 9, 9)), + ATC2 = paste("ATCCLAS2", substr(.data$CMDECOD, 9, 9)), + ATC3 = paste("ATCCLAS3", substr(.data$CMDECOD, 9, 9)), + ATC4 = paste("ATCCLAS4", substr(.data$CMDECOD, 9, 9)) + ) %>% + dplyr::mutate(CMINDC = sample(c( + "Nausea", "Hypertension", "Urticaria", "Fever", + "Asthma", "Infection", "Diabete", "Diarrhea", "Pneumonia" + ), dplyr::n(), replace = TRUE)) %>% + dplyr::mutate(CMDOSE = sample(1:99, dplyr::n(), replace = TRUE)) %>% + dplyr::mutate(CMTRT = substr(.data$CMDECOD, 9, 13)) %>% + dplyr::mutate(CMDOSU = sample(c( + "ug/mL", "ug/kg/day", "%", "uL", "DROP", + "umol/L", "mg", "mg/breath", "ug" + ), dplyr::n(), replace = TRUE)) %>% + dplyr::mutate(CMROUTE = sample(c( + "INTRAVENOUS", "ORAL", "NASAL", + "INTRAMUSCULAR", "SUBCUTANEOUS", "INHALED", "RECTAL", "UNKNOWN" + ), dplyr::n(), replace = TRUE)) %>% + dplyr::mutate(CMDOSFRQ = sample(c( + "Q4W", "QN", "Q4H", "UNKNOWN", "TWICE", + "Q4H", "QD", "TID", "4 TIMES PER MONTH" + ), dplyr::n(), replace = TRUE)) + + # Adding labels + tmp_dt <- scda::synthetic_cdisc_dataset("latest", "adcm") + formatters::var_labels(tmc_ex_adcm) <- as.character(formatters::var_labels(tmp_dt)[names(tmc_ex_adcm)]) + rm(tmp_dt) + + save(tmc_ex_adcm, file = "data/tmc_ex_adcm.rda", compress = "xz") +} +``` + +## Generate Data + +```{r generate data, eval=FALSE} +# Generate & load adsl +tmp_fol <- getwd() +setwd(dirname(tmp_fol)) +generate_adsl() +load("data/tmc_ex_adsl.rda") + +# Generate other datasets +generate_adae() +generate_adlb() +generate_adrs() +generate_adtte() +generate_adcm() + +setwd(tmp_fol) +```