Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

78 simplify joinkeys@main #233

Merged
merged 17 commits into from
Nov 20, 2023
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Improved input validation and used the `teal::validate_inputs` mechanism to send validation messages to the output panel.
* Removed `purrr` from dependencies.
* Added argument checks to `tm_g_patient_profile`.
* Modified examples to utilize new `teal_data` and `join_keys` solutions.

### Breaking changes

Expand Down
93 changes: 34 additions & 59 deletions R/tm_g_ae_oview.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,51 @@
#' @export
#'
#' @examples
#' library(nestcolor)
#' data <- cdisc_data() |>
#' within({
#' library(nestcolor)
#' ADSL <- rADSL
#' ADAE <- rADAE
#' add_event_flags <- function(dat) {
#' dat <- dat |>
#' mutate(
#' TMPFL_SER = AESER == "Y",
#' TMPFL_REL = AEREL == "Y",
#' TMPFL_GR5 = AETOXGR == "5",
#' AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X"),
#' AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")
#' )
#' labels <- c(
#' "Serious AE", "Related AE", "Grade 5 AE",
#' "AE related to A: Drug X", "AE related to B: Placebo"
#' )
#' cols <- c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
#' for (i in seq_along(labels)) {
#' attr(dat[[cols[i]]], "label") <- labels[i]
#' }
#' dat
#' }
#' ADAE <- add_event_flags(ADAE)
#' })
#'
#' ADSL <- osprey::rADSL
#' ADAE <- osprey::rADAE
#' datanames(data) <- c("ADSL", "ADAE")
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' # Add additional dummy causality flags.
#' add_event_flags <- function(dat) {
#' dat <- dat %>%
#' dplyr::mutate(
#' TMPFL_SER = AESER == "Y",
#' TMPFL_REL = AEREL == "Y",
#' TMPFL_GR5 = AETOXGR == "5",
#' AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X"),
#' AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")
#' )
#' labels <- c(
#' "Serious AE", "Related AE", "Grade 5 AE",
#' "AE related to A: Drug X", "AE related to B: Placebo"
#' )
#' cols <- c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
#' for (i in seq_along(labels)) {
#' attr(dat[[cols[i]]], "label") <- labels[i]
#' }
#' dat
#' }
#' ADAE <- ADAE %>% add_event_flags()
#' ADAE <- data[["ADAE"]]
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", ADSL, code = "ADSL <- osprey::rADSL"),
#' cdisc_dataset("ADAE", ADAE,
#' code =
#' "ADAE <- osprey::rADAE
#' add_event_flags <- function(dat) {
#' dat <- dat %>%
#' dplyr::mutate(
#' TMPFL_SER = AESER == 'Y',
#' TMPFL_REL = AEREL == 'Y',
#' TMPFL_GR5 = AETOXGR == '5',
#' AEREL1 = (AEREL == 'Y' & ACTARM == 'A: Drug X'),
#' AEREL2 = (AEREL == 'Y' & ACTARM == 'B: Placebo')
#' )
#' labels <- c(
#' 'Serious AE',
#' 'Related AE',
#' 'Grade 5 AE',
#' 'AE related to A: Drug X',
#' 'AE related to B: Placebo'
#' )
#' cols <- c('TMPFL_SER', 'TMPFL_REL', 'TMPFL_GR5', 'AEREL1', 'AEREL2')
#' for (i in seq_along(labels)) {
#' attr(dat[[cols[i]]], 'label') <- labels[i]
#' }
#' dat
#' }
#' # Generating user-defined event flags.
#' ADAE <- ADAE %>% add_event_flags()"
#' ),
#' check = TRUE
#' ),
#' data = data,
#' modules = modules(
#' tm_g_ae_oview(
#' label = "AE Overview",
#' dataname = "ADAE",
#' arm_var = teal.transform::choices_selected(
#' arm_var = choices_selected(
#' selected = "ACTARM",
#' choices = c("ACTARM", "ACTARMCD")
#' ),
#' flag_var_anl = teal.transform::choices_selected(
#' flag_var_anl = choices_selected(
#' selected = "AEREL1",
#' choices = teal.transform::variable_choices(
#' choices = variable_choices(
#' ADAE,
#' c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
#' ),
Expand All @@ -98,6 +72,7 @@
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
tm_g_ae_oview <- function(label,
dataname,
arm_var,
Expand Down
19 changes: 11 additions & 8 deletions R/tm_g_ae_sub.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
#' @export
#'
#' @examples
#' # Example using stream (ADaM) dataset
#' ADSL <- osprey::rADSL
#' ADAE <- osprey::rADAE
# Example using stream (ADaM) dataset
#' data <- cdisc_data() |>
#' within({
#' ADSL <- rADSL
#' ADAE <- rADAE
#' })
#'
#' datanames(data) <- c("ADSL", "ADAE")
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", ADSL, code = "ADSL <- osprey::rADSL"),
#' cdisc_dataset("ADAE", ADAE, code = "ADAE <- osprey::rADAE"),
#' check = TRUE
#' ),
#' data = data,
#' modules = modules(
#' tm_g_ae_sub(
#' label = "AE by Subgroup",
Expand All @@ -46,6 +48,7 @@
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
tm_g_ae_sub <- function(label,
dataname,
arm_var,
Expand Down
65 changes: 27 additions & 38 deletions R/tm_g_butterfly.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,69 +40,58 @@
#' @template author_liaoc10
#'
#' @examples
# Example using stream (ADaM) dataset
#' data <- cdisc_data() |>
#' within({
#' library(dplyr)
#' library(nestcolor)
#' set.seed(23)
#' ADSL <- rADSL
#' ADAE <- rADAE
#' ADSL <- mutate(ADSL, DOSE = paste(sample(1:3, n(), replace = TRUE), "UG"))
#' ADAE <- mutate(
#' ADAE,
#' flag1 = ifelse(AETOXGR == 1, 1, 0),
#' flag2 = ifelse(AETOXGR == 2, 1, 0),
#' flag3 = ifelse(AETOXGR == 3, 1, 0),
#' flag1_filt = rep("Y", n())
#' )
#' })
#'
#' # Example using stream (ADaM) dataset
#' library(dplyr)
#' library(nestcolor)
#'
#' set.seed(23)
#' ADSL <- osprey::rADSL
#' ADAE <- osprey::rADAE
#' ADSL <- mutate(ADSL, DOSE = paste(sample(1:3, n(), replace = TRUE), "UG"))
#' ADAE <- mutate(
#' ADAE,
#' flag1 = ifelse(AETOXGR == 1, 1, 0),
#' flag2 = ifelse(AETOXGR == 2, 1, 0),
#' flag3 = ifelse(AETOXGR == 3, 1, 0),
#' flag1_filt = rep("Y", n())
#' )
#' datanames(data) <- c("ADSL", "ADAE")
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", ADSL,
#' code = "ADSL <- osprey::rADSL
#' set.seed(23)
#' ADSL <- mutate(ADSL, DOSE = paste(sample(1:3, n(), replace = TRUE), 'UG'))"
#' ),
#' cdisc_dataset("ADAE", ADAE,
#' code = "ADAE <- osprey::rADAE
#' ADAE <- mutate(ADAE,
#' flag1 = ifelse(AETOXGR == 1, 1, 0),
#' flag2 = ifelse(AETOXGR == 2, 1, 0),
#' flag3 = ifelse(AETOXGR == 3, 1, 0),
#' flag1_filt = rep('Y', n()))"
#' ),
#' check = TRUE
#' ),
#' data = data,
#' modules = modules(
#' tm_g_butterfly(
#' label = "Butterfly Plot",
#' dataname = "ADAE",
#' right_var = teal.transform::choices_selected(
#' right_var = choices_selected(
#' selected = "SEX",
#' choices = c("SEX", "ARM", "RACE")
#' ),
#' left_var = teal.transform::choices_selected(
#' left_var = choices_selected(
#' selected = "RACE",
#' choices = c("SEX", "ARM", "RACE")
#' ),
#' category_var = teal.transform::choices_selected(
#' category_var = choices_selected(
#' selected = "AEBODSYS",
#' choices = c("AEDECOD", "AEBODSYS")
#' ),
#' color_by_var = teal.transform::choices_selected(
#' color_by_var = choices_selected(
#' selected = "AETOXGR",
#' choices = c("AETOXGR", "None")
#' ),
#' count_by_var = teal.transform::choices_selected(
#' count_by_var = choices_selected(
#' selected = "# of patients",
#' choices = c("# of patients", "# of AEs")
#' ),
#' facet_var = teal.transform::choices_selected(
#' facet_var = choices_selected(
#' selected = NULL,
#' choices = c("RACE", "SEX", "ARM")
#' ),
#' sort_by_var = teal.transform::choices_selected(
#' sort_by_var = choices_selected(
#' selected = "count",
#' choices = c("count", "alphabetical")
#' ),
Expand Down
21 changes: 11 additions & 10 deletions R/tm_g_events_term_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,30 @@
#' @author Molly He (hey59) \email{[email protected]}
#'
#' @examples
#' library(nestcolor)
#' data <- cdisc_data() |>
#' within({
#' library(nestcolor)
#' ADSL <- rADSL
#' ADAE <- rADAE
#' })
#'
#' ADSL <- osprey::rADSL
#' ADAE <- osprey::rADAE
#' datanames(data) <- c("ADSL", "ADAE")
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", ADSL, code = "ADSL <- osprey::rADSL"),
#' cdisc_dataset("ADAE", ADAE, code = "ADAE <- osprey::rADAE"),
#' check = TRUE
#' ),
#' data = data,
#' modules = modules(
#' tm_g_events_term_id(
#' label = "Common AE",
#' dataname = "ADAE",
#' term_var = teal.transform::choices_selected(
#' term_var = choices_selected(
#' selected = "AEDECOD",
#' choices = c(
#' "AEDECOD", "AETERM",
#' "AEHLT", "AELLT", "AEBODSYS"
#' )
#' ),
#' arm_var = teal.transform::choices_selected(
#' arm_var = choices_selected(
#' selected = "ACTARMCD",
#' choices = c("ACTARM", "ACTARMCD")
#' ),
Expand Down
Loading