From bd74b80ef3e9673319337e509ad1013f8ddb5e69 Mon Sep 17 00:00:00 2001 From: kartikeya kirar Date: Mon, 20 Nov 2023 16:30:48 +0530 Subject: [PATCH] Update docs to use the new `teal_data` instead of `TealData` (#245) fixes https://github.com/insightsengineering/teal.goshawk/issues/243 part of https://github.com/insightsengineering/nestdevs-tasks/issues/41 https://github.com/insightsengineering/teal.data/pull/184 - [x] add the news section for change. - [x] update the examples in the documentation to pass teal_data. - [x] update join_keys calls once the pull request is completed at https://github.com/insightsengineering/teal.data/pull/184. - [x] Revise and update the vignettes accordingly. - [ ] make version bump once https://github.com/insightsengineering/teal.data/pull/184. is merged. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: vedhav --- DESCRIPTION | 6 +- NEWS.md | 4 + R/tm_g_gh_boxplot.R | 172 +++++++---------- R/tm_g_gh_correlationplot.R | 228 ++++++++-------------- R/tm_g_gh_density_distribution_plot.R | 117 +++++------- R/tm_g_gh_lineplot.R | 118 +++++------- R/tm_g_gh_scatterplot.R | 115 +++++------ R/tm_g_gh_spaghettiplot.R | 163 ++++++---------- man/tm_g_gh_boxplot.Rd | 182 +++++++----------- man/tm_g_gh_correlationplot.Rd | 232 +++++++++-------------- man/tm_g_gh_density_distribution_plot.Rd | 117 +++++------- man/tm_g_gh_lineplot.Rd | 120 +++++------- man/tm_g_gh_scatterplot.Rd | 115 +++++------ man/tm_g_gh_spaghettiplot.Rd | 169 +++++++---------- vignettes/teal-goshawk.Rmd | 45 +++-- 15 files changed, 734 insertions(+), 1169 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5b089549..089a0083 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Depends: goshawk (>= 0.1.15), R (>= 3.6), shiny, - teal (>= 0.14.0) + teal (>= 0.14.0.9019) Imports: checkmate, colourpicker, @@ -47,7 +47,7 @@ Imports: teal.code (>= 0.4.0), teal.logger (>= 0.1.1), teal.reporter (>= 0.2.0), - teal.transform (>= 0.4.0), + teal.transform (>= 0.4.0.9007), teal.widgets (>= 0.4.0), tidyr Suggests: @@ -55,7 +55,7 @@ Suggests: nestcolor (>= 0.1.0), rmarkdown, stringr, - teal.data (>= 0.3.0), + teal.data (>= 0.3.0.9010), tern (>= 0.7.10), testthat (>= 2.0), utils diff --git a/NEWS.md b/NEWS.md index d158eb64..a459422f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # teal.goshawk 0.1.15.9002 +### Enhancements + +* Updated the documentation and vignettes to demonstrate method to pass `teal_data` object to `teal::init()`. + # teal.goshawk 0.1.15 ### Enhancements diff --git a/R/tm_g_gh_boxplot.R b/R/tm_g_gh_boxplot.R index 0ab843d3..ed584940 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -48,121 +48,77 @@ #' @examples #' #' # Example using ADaM structure analysis dataset. +#' data <- teal_data() +#' data <- within(data, { +#' library(dplyr) +#' library(nestcolor) #' -#' library(dplyr) -#' library(nestcolor) +#' # original ARM value = dose value +#' arm_mapping <- list( +#' "A: Drug X" = "150mg QD", +#' "B: Placebo" = "Placebo", +#' "C: Combination" = "Combination" +#' ) +#' set.seed(1) +#' ADSL <- goshawk::rADSL +#' ADLB <- goshawk::rADLB +#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) +#' ADLB <- ADLB %>% +#' dplyr::mutate( +#' AVISITCD = dplyr::case_when( +#' AVISIT == "SCREENING" ~ "SCR", +#' AVISIT == "BASELINE" ~ "BL", +#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' TRUE ~ as.character(NA) +#' ), +#' AVISITCDN = dplyr::case_when( +#' AVISITCD == "SCR" ~ -2, +#' AVISITCD == "BL" ~ 0, +#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), +#' TRUE ~ as.numeric(NA) +#' ), +#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), +#' TRTORD = dplyr::case_when( +#' ARMCD == "ARM C" ~ 1, +#' ARMCD == "ARM B" ~ 2, +#' ARMCD == "ARM A" ~ 3 +#' ), +#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), +#' ARM = factor(ARM) %>% reorder(TRTORD), +#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), +#' ACTARM = factor(ACTARM) %>% reorder(TRTORD), +#' ANRLO = 50, +#' ANRHI = 75 +#' ) %>% +#' dplyr::rowwise() %>% +#' dplyr::group_by(PARAMCD) %>% +#' dplyr::mutate(LBSTRESC = ifelse( +#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC +#' )) %>% +#' dplyr::mutate(LBSTRESC = ifelse( +#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC +#' )) %>% +#' ungroup() #' -#' # original ARM value = dose value -#' arm_mapping <- list( -#' "A: Drug X" = "150mg QD", -#' "B: Placebo" = "Placebo", -#' "C: Combination" = "Combination" -#' ) +#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] +#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" +#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" #' -#' set.seed(1) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( -#' AVISIT == "SCREENING" ~ "SCR", -#' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), -#' TRUE ~ as.character(NA) -#' ), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == "SCR" ~ -2, -#' AVISITCD == "BL" ~ 0, -#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), -#' TRUE ~ as.numeric(NA) -#' ), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == "ARM C" ~ 1, -#' ARMCD == "ARM B" ~ 2, -#' ARMCD == "ARM A" ~ 3 -#' ), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD), -#' ANRLO = 50, -#' ANRHI = 75 -#' ) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC -#' )) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC -#' )) %>% -#' ungroup() +#' # add LLOQ and ULOQ variables +#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) +#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +#' }) #' -#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] -#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" -#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" +#' datanames <- c("ADSL", "ADLB") +#' datanames(data) <- datanames #' -#' # add LLOQ and ULOQ variables -#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), -#' teal.data::cdisc_dataset( -#' "ADLB", -#' ADLB, -#' code = " -#' set.seed(1) -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == 'SCREENING' ~ 'SCR', -#' AVISIT == 'BASELINE' ~ 'BL', -#' grepl('WEEK', AVISIT) ~ paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), -#' TRUE ~ as.character(NA)), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == 'SCR' ~ -2, -#' AVISITCD == 'BL' ~ 0, -#' grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), -#' TRUE ~ as.numeric(NA)), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == 'ARM C' ~ 1, -#' ARMCD == 'ARM B' ~ 2, -#' ARMCD == 'ARM A' ~ 3), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD), -#' ANRLO = 50, -#' ANRHI = 75) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) %>% -#' ungroup() -#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] -#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']] -#' attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit' -#' attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit' -#' # add LLOQ and ULOQ variables -#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -#' ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')", -#' vars = list(ADSL = adsl, arm_mapping = arm_mapping) -#' ), -#' check = FALSE # to shorten the example check = FALSE, in real scenarios use check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.goshawk::tm_g_gh_boxplot( #' label = "Box Plot", diff --git a/R/tm_g_gh_correlationplot.R b/R/tm_g_gh_correlationplot.R index 0c99a31e..3df43318 100644 --- a/R/tm_g_gh_correlationplot.R +++ b/R/tm_g_gh_correlationplot.R @@ -52,156 +52,95 @@ #' @examples #' #' # Example using ADaM structure analysis dataset. +#' data <- teal_data() +#' data <- within(data, { +#' # original ARM value = dose value +#' arm_mapping <- list( +#' "A: Drug X" = "150mg QD", +#' "B: Placebo" = "Placebo", +#' "C: Combination" = "Combination" +#' ) +#' color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") +#' # assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA" +#' shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) #' -#' # original ARM value = dose value -#' arm_mapping <- list( -#' "A: Drug X" = "150mg QD", -#' "B: Placebo" = "Placebo", -#' "C: Combination" = "Combination" -#' ) -#' color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") -#' # assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA" -#' shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) -#' -#' set.seed(1) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == "SCREENING" ~ "SCR", -#' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ -#' paste( -#' "W", -#' trimws( -#' substr( -#' AVISIT, -#' start = 6, -#' stop = stringr::str_locate(AVISIT, "DAY") - 1 +#' set.seed(1) +#' ADSL <- goshawk::rADSL +#' ADLB <- goshawk::rADLB +#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) +#' ADLB <- ADLB %>% +#' dplyr::mutate(AVISITCD = dplyr::case_when( +#' AVISIT == "SCREENING" ~ "SCR", +#' AVISIT == "BASELINE" ~ "BL", +#' grepl("WEEK", AVISIT) ~ +#' paste( +#' "W", +#' trimws( +#' substr( +#' AVISIT, +#' start = 6, +#' stop = stringr::str_locate(AVISIT, "DAY") - 1 +#' ) #' ) -#' ) -#' ), -#' TRUE ~ NA_character_ -#' )) %>% -#' dplyr::mutate(AVISITCDN = dplyr::case_when( -#' AVISITCD == "SCR" ~ -2, -#' AVISITCD == "BL" ~ 0, -#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), -#' TRUE ~ NA_real_ -#' )) %>% -#' # use ARMCD values to order treatment in visualization legend -#' dplyr::mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, -#' ifelse(grepl("B", ARMCD), 2, -#' ifelse(grepl("A", ARMCD), 3, NA) -#' ) -#' )) %>% -#' dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% -#' dplyr::mutate(ARM = factor(ARM) %>% -#' reorder(TRTORD)) %>% -#' dplyr::mutate( -#' ANRHI = dplyr::case_when( -#' PARAMCD == "ALT" ~ 60, -#' PARAMCD == "CRP" ~ 70, -#' PARAMCD == "IGA" ~ 80, -#' TRUE ~ NA_real_ -#' ), -#' ANRLO = dplyr::case_when( -#' PARAMCD == "ALT" ~ 20, -#' PARAMCD == "CRP" ~ 30, -#' PARAMCD == "IGA" ~ 40, +#' ), +#' TRUE ~ NA_character_ +#' )) %>% +#' dplyr::mutate(AVISITCDN = dplyr::case_when( +#' AVISITCD == "SCR" ~ -2, +#' AVISITCD == "BL" ~ 0, +#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ NA_real_ -#' ) -#' ) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC -#' )) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC -#' )) %>% -#' ungroup() -#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" -#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" +#' )) %>% +#' # use ARMCD values to order treatment in visualization legend +#' dplyr::mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, +#' ifelse(grepl("B", ARMCD), 2, +#' ifelse(grepl("A", ARMCD), 3, NA) +#' ) +#' )) %>% +#' dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% +#' dplyr::mutate(ARM = factor(ARM) %>% +#' reorder(TRTORD)) %>% +#' dplyr::mutate( +#' ANRHI = dplyr::case_when( +#' PARAMCD == "ALT" ~ 60, +#' PARAMCD == "CRP" ~ 70, +#' PARAMCD == "IGA" ~ 80, +#' TRUE ~ NA_real_ +#' ), +#' ANRLO = dplyr::case_when( +#' PARAMCD == "ALT" ~ 20, +#' PARAMCD == "CRP" ~ 30, +#' PARAMCD == "IGA" ~ 40, +#' TRUE ~ NA_real_ +#' ) +#' ) %>% +#' dplyr::rowwise() %>% +#' dplyr::group_by(PARAMCD) %>% +#' dplyr::mutate(LBSTRESC = ifelse( +#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC +#' )) %>% +#' dplyr::mutate(LBSTRESC = ifelse( +#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC +#' )) %>% +#' ungroup() +#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] +#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" +#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" #' -#' # add LLOQ and ULOQ variables -#' ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -#' ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM") +#' # add LLOQ and ULOQ variables +#' ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB) +#' ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM") +#' }) #' -#' app <- teal::init( -#' data = teal.data::cdisc_data( -#' teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), -#' teal.data::cdisc_dataset( -#' "ADLB", -#' ADLB, -#' code = "set.seed(1) -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == 'SCREENING' ~ 'SCR', -#' AVISIT == 'BASELINE' ~ 'BL', -#' grepl('WEEK', AVISIT) ~ -#' paste( -#' 'W', -#' trimws( -#' substr( -#' AVISIT, -#' start = 6, -#' stop = stringr::str_locate(AVISIT, 'DAY') - 1 -#' ) -#' ) -#' ), -#' TRUE ~ NA_character_)) %>% -#' dplyr::mutate(AVISITCDN = dplyr::case_when( -#' AVISITCD == 'SCR' ~ -2, -#' AVISITCD == 'BL' ~ 0, -#' grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), -#' TRUE ~ NA_real_)) %>% -#' # use ARMCD values to order treatment in visualization legend -#' dplyr::mutate(TRTORD = ifelse(grepl('C', ARMCD), 1, -#' ifelse(grepl('B', ARMCD), 2, -#' ifelse(grepl('A', ARMCD), 3, NA)))) %>% -#' dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% -#' dplyr::mutate(ARM = factor(ARM) %>% -#' reorder(TRTORD)) %>% -#' dplyr::mutate( -#' ANRHI = dplyr::case_when( -#' PARAMCD == 'ALT' ~ 60, -#' PARAMCD == 'CRP' ~ 70, -#' PARAMCD == 'IGA' ~ 80, -#' TRUE ~ NA_real_ -#' ), -#' ANRLO = dplyr::case_when( -#' PARAMCD == 'ALT' ~ 20, -#' PARAMCD == 'CRP' ~ 30, -#' PARAMCD == 'IGA' ~ 40, -#' TRUE ~ NA_real_ -#' )) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) %>% -#' dplyr::mutate(LBSTRESC = ifelse( -#' USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) %>% -#' ungroup() -#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] -#' attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit' -#' attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit' +#' datanames <- c("ADSL", "ADLB") +#' datanames(data) <- datanames #' -#' # add LLOQ and ULOQ variables -#' ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -#' ADLB <- left_join(ADLB, ADLB_LOQS, by = 'PARAM')", -#' vars = list(arm_mapping = arm_mapping) -#' ), -#' check = TRUE -#' ), +#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' +#' app <- teal::init( +#' data = data, #' modules = teal::modules( #' teal.goshawk::tm_g_gh_correlationplot( #' label = "Correlation Plot", @@ -244,6 +183,7 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' tm_g_gh_correlationplot <- function(label, dataname, param_var = "PARAMCD", diff --git a/R/tm_g_gh_density_distribution_plot.R b/R/tm_g_gh_density_distribution_plot.R index bdd062b8..1e282b6c 100644 --- a/R/tm_g_gh_density_distribution_plot.R +++ b/R/tm_g_gh_density_distribution_plot.R @@ -35,82 +35,54 @@ #' @examples #' #' # Example using ADaM structure analysis dataset. -#' -#' library(dplyr) -#' -#' # original ARM value = dose value -#' arm_mapping <- list( -#' "A: Drug X" = "150mg QD", -#' "B: Placebo" = "Placebo", -#' "C: Combination" = "Combination" -#' ) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( -#' AVISIT == "SCREENING" ~ "SCR", -#' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), -#' TRUE ~ as.character(NA) -#' ), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == "SCR" ~ -2, -#' AVISITCD == "BL" ~ 0, -#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), -#' TRUE ~ as.numeric(NA) -#' ), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == "ARM C" ~ 1, -#' ARMCD == "ARM B" ~ 2, -#' ARMCD == "ARM A" ~ 3 -#' ), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD) +#' data <- teal_data() +#' data <- within(data, { +#' library(dplyr) +#' # original ARM value = dose value +#' arm_mapping <- list( +#' "A: Drug X" = "150mg QD", +#' "B: Placebo" = "Placebo", +#' "C: Combination" = "Combination" #' ) +#' ADSL <- goshawk::rADSL +#' ADLB <- goshawk::rADLB +#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) +#' ADLB <- ADLB %>% +#' dplyr::mutate( +#' AVISITCD = dplyr::case_when( +#' AVISIT == "SCREENING" ~ "SCR", +#' AVISIT == "BASELINE" ~ "BL", +#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' TRUE ~ as.character(NA) +#' ), +#' AVISITCDN = dplyr::case_when( +#' AVISITCD == "SCR" ~ -2, +#' AVISITCD == "BL" ~ 0, +#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), +#' TRUE ~ as.numeric(NA) +#' ), +#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), +#' TRTORD = dplyr::case_when( +#' ARMCD == "ARM C" ~ 1, +#' ARMCD == "ARM B" ~ 2, +#' ARMCD == "ARM A" ~ 3 +#' ), +#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), +#' ARM = factor(ARM) %>% reorder(TRTORD), +#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), +#' ACTARM = factor(ACTARM) %>% reorder(TRTORD) +#' ) #' -#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] +#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' }) +#' +#' datanames <- c("ADSL", "ADLB") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), -#' teal.data::cdisc_dataset( -#' "ADLB", -#' ADLB, -#' code = "ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == 'SCREENING' ~ 'SCR', -#' AVISIT == 'BASELINE' ~ 'BL', -#' grepl('WEEK', AVISIT) ~ -#' paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), -#' TRUE ~ as.character(NA)), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == 'SCR' ~ -2, -#' AVISITCD == 'BL' ~ 0, -#' grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), -#' TRUE ~ as.numeric(NA)), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == 'ARM C' ~ 1, -#' ARMCD == 'ARM B' ~ 2, -#' ARMCD == 'ARM A' ~ 3), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD)) -#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] -#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]", -#' vars = list(arm_mapping = arm_mapping) -#' ), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.goshawk::tm_g_gh_density_distribution_plot( #' label = "Density Distribution Plot", @@ -138,6 +110,7 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' tm_g_gh_density_distribution_plot <- function(label, # nolint dataname, param_var, diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index 564afcf0..0cce6394 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -53,82 +53,57 @@ #' @examples #' #' # Example using ADaM structure analysis dataset. +#' data <- teal_data() +#' data <- within(data, { +#' library(dplyr) +#' library(stringr) +#' library(nestcolor) #' -#' library(dplyr) -#' library(stringr) -#' library(nestcolor) +#' # original ARM value = dose value +#' arm_mapping <- list( +#' "A: Drug X" = "150mg QD", +#' "B: Placebo" = "Placebo", +#' "C: Combination" = "Combination" +#' ) #' -#' # original ARM value = dose value -#' arm_mapping <- list( -#' "A: Drug X" = "150mg QD", -#' "B: Placebo" = "Placebo", -#' "C: Combination" = "Combination" -#' ) +#' ADSL <- goshawk::rADSL +#' ADLB <- goshawk::rADLB +#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) +#' ADLB <- ADLB %>% +#' dplyr::mutate( +#' AVISITCD = dplyr::case_when( +#' AVISIT == "SCREENING" ~ "SCR", +#' AVISIT == "BASELINE" ~ "BL", +#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' TRUE ~ as.character(NA) +#' ), +#' AVISITCDN = dplyr::case_when( +#' AVISITCD == "SCR" ~ -2, +#' AVISITCD == "BL" ~ 0, +#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), +#' TRUE ~ as.numeric(NA) +#' ), +#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), +#' TRTORD = dplyr::case_when( +#' ARMCD == "ARM C" ~ 1, +#' ARMCD == "ARM B" ~ 2, +#' ARMCD == "ARM A" ~ 3 +#' ), +#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), +#' ARM = factor(ARM) %>% reorder(TRTORD), +#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), +#' ACTARM = factor(ACTARM) %>% reorder(TRTORD) +#' ) +#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] +#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' }) #' -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( -#' AVISIT == "SCREENING" ~ "SCR", -#' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), -#' TRUE ~ as.character(NA) -#' ), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == "SCR" ~ -2, -#' AVISITCD == "BL" ~ 0, -#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), -#' TRUE ~ as.numeric(NA) -#' ), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == "ARM C" ~ 1, -#' ARMCD == "ARM B" ~ 2, -#' ARMCD == "ARM A" ~ 3 -#' ), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD) -#' ) -#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' datanames <- c("ADSL", "ADLB") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), -#' teal.data::cdisc_dataset("ADLB", ADLB, -#' code = "ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == 'SCREENING' ~ 'SCR', -#' AVISIT == 'BASELINE' ~ 'BL', -#' grepl('WEEK', AVISIT) ~ -#' paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), -#' TRUE ~ as.character(NA)), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == 'SCR' ~ -2, -#' AVISITCD == 'BL' ~ 0, -#' grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), -#' TRUE ~ as.numeric(NA)), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == 'ARM C' ~ 1, -#' ARMCD == 'ARM B' ~ 2, -#' ARMCD == 'ARM A' ~ 3), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD)) -#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] -#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]", -#' vars = list(ADSL = adsl, arm_mapping = arm_mapping) -#' ), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.goshawk::tm_g_gh_lineplot( #' label = "Line Plot", @@ -148,6 +123,7 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' tm_g_gh_lineplot <- function(label, dataname, param_var, diff --git a/R/tm_g_gh_scatterplot.R b/R/tm_g_gh_scatterplot.R index 752dae0e..180b70ca 100644 --- a/R/tm_g_gh_scatterplot.R +++ b/R/tm_g_gh_scatterplot.R @@ -38,81 +38,56 @@ #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' #' @examples +#' #' # Example using ADaM structure analysis dataset. +#' data <- teal_data() +#' data <- within(data, { +#' # original ARM value = dose value +#' arm_mapping <- list( +#' "A: Drug X" = "150mg QD", +#' "B: Placebo" = "Placebo", +#' "C: Combination" = "Combination" +#' ) #' -#' # original ARM value = dose value -#' arm_mapping <- list( -#' "A: Drug X" = "150mg QD", -#' "B: Placebo" = "Placebo", -#' "C: Combination" = "Combination" -#' ) +#' ADSL <- goshawk::rADSL +#' ADLB <- goshawk::rADLB +#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) +#' ADLB <- ADLB %>% +#' dplyr::mutate( +#' AVISITCD = dplyr::case_when( +#' AVISIT == "SCREENING" ~ "SCR", +#' AVISIT == "BASELINE" ~ "BL", +#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' TRUE ~ as.character(NA) +#' ), +#' AVISITCDN = dplyr::case_when( +#' AVISITCD == "SCR" ~ -2, +#' AVISITCD == "BL" ~ 0, +#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), +#' TRUE ~ as.numeric(NA) +#' ), +#' AVISITCD = factor(AVISITCD) %>% stats::reorder(AVISITCDN), +#' TRTORD = dplyr::case_when( +#' ARMCD == "ARM C" ~ 1, +#' ARMCD == "ARM B" ~ 2, +#' ARMCD == "ARM A" ~ 3 +#' ), +#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), +#' ARM = factor(ARM) %>% stats::reorder(TRTORD), +#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), +#' ACTARM = factor(ACTARM) %>% stats::reorder(TRTORD) +#' ) +#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] +#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' }) +#' +#' datanames <- c("ADSL", "ADLB") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( -#' AVISIT == "SCREENING" ~ "SCR", -#' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), -#' TRUE ~ as.character(NA) -#' ), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == "SCR" ~ -2, -#' AVISITCD == "BL" ~ 0, -#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), -#' TRUE ~ as.numeric(NA) -#' ), -#' AVISITCD = factor(AVISITCD) %>% stats::reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == "ARM C" ~ 1, -#' ARMCD == "ARM B" ~ 2, -#' ARMCD == "ARM A" ~ 3 -#' ), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% stats::reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% stats::reorder(TRTORD) -#' ) -#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), -#' teal.data::cdisc_dataset( -#' "ADLB", -#' ADLB, -#' code = "ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == 'SCREENING' ~ 'SCR', -#' AVISIT == 'BASELINE' ~ 'BL', -#' grepl('WEEK', AVISIT) ~ -#' paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), -#' TRUE ~ as.character(NA)), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == 'SCR' ~ -2, -#' AVISITCD == 'BL' ~ 0, -#' grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), -#' TRUE ~ as.numeric(NA)), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == 'ARM C' ~ 1, -#' ARMCD == 'ARM B' ~ 2, -#' ARMCD == 'ARM A' ~ 3), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD)) -#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] -#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]", -#' vars = list(ADSL = adsl, arm_mapping = arm_mapping) -#' ), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.goshawk::tm_g_gh_scatterplot( #' label = "Scatter Plot", diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index 0add074f..2a4d3ee6 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -57,113 +57,72 @@ #' @examples #' #' # Example using ADaM structure analysis dataset. +#' data <- teal_data() +#' data <- within(data, { +#' library(dplyr) #' -#' library(dplyr) +#' # original ARM value = dose value +#' arm_mapping <- list( +#' "A: Drug X" = "150mg QD", +#' "B: Placebo" = "Placebo", +#' "C: Combination" = "Combination" +#' ) +#' set.seed(1) +#' ADSL <- goshawk::rADSL +#' ADLB <- goshawk::rADLB +#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) +#' ADLB <- ADLB %>% +#' dplyr::mutate( +#' AVISITCD = dplyr::case_when( +#' AVISIT == "SCREENING" ~ "SCR", +#' AVISIT == "BASELINE" ~ "BL", +#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' TRUE ~ as.character(NA) +#' ), +#' AVISITCDN = dplyr::case_when( +#' AVISITCD == "SCR" ~ -2, +#' AVISITCD == "BL" ~ 0, +#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), +#' TRUE ~ as.numeric(NA) +#' ), +#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), +#' TRTORD = dplyr::case_when( +#' ARMCD == "ARM C" ~ 1, +#' ARMCD == "ARM B" ~ 2, +#' ARMCD == "ARM A" ~ 3 +#' ), +#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), +#' ARM = factor(ARM) %>% reorder(TRTORD), +#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), +#' ACTARM = factor(ACTARM) %>% reorder(TRTORD), +#' ANRLO = 30, +#' ANRHI = 75 +#' ) %>% +#' dplyr::rowwise() %>% +#' dplyr::group_by(PARAMCD) %>% +#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC +#' )) %>% +#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC +#' )) %>% +#' ungroup() +#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] +#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" +#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" #' -#' # original ARM value = dose value -#' arm_mapping <- list( -#' "A: Drug X" = "150mg QD", -#' "B: Placebo" = "Placebo", -#' "C: Combination" = "Combination" -#' ) -#' set.seed(1) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( -#' AVISIT == "SCREENING" ~ "SCR", -#' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), -#' TRUE ~ as.character(NA) -#' ), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == "SCR" ~ -2, -#' AVISITCD == "BL" ~ 0, -#' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), -#' TRUE ~ as.numeric(NA) -#' ), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == "ARM C" ~ 1, -#' ARMCD == "ARM B" ~ 2, -#' ARMCD == "ARM A" ~ 3 -#' ), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD), -#' ANRLO = 30, -#' ANRHI = 75 -#' ) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC -#' )) %>% -#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC -#' )) %>% -#' ungroup() -#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -#' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] -#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" -#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" +#' # add LLOQ and ULOQ variables +#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) +#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +#' }) #' -#' # add LLOQ and ULOQ variables -#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +#' datanames <- c("ADSL", "ADLB") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), -#' teal.data::cdisc_dataset( -#' "ADLB", -#' ADLB, -#' code = "set.seed(1) -#' ADLB <- goshawk::rADLB -#' var_labels <- lapply(ADLB, function(x) attributes(x)$label) -#' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( -#' AVISIT == 'SCREENING' ~ 'SCR', -#' AVISIT == 'BASELINE' ~ 'BL', -#' grepl('WEEK', AVISIT) ~ -#' paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), -#' TRUE ~ as.character(NA)), -#' AVISITCDN = dplyr::case_when( -#' AVISITCD == 'SCR' ~ -2, -#' AVISITCD == 'BL' ~ 0, -#' grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), -#' TRUE ~ as.numeric(NA)), -#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( -#' ARMCD == 'ARM C' ~ 1, -#' ARMCD == 'ARM B' ~ 2, -#' ARMCD == 'ARM A' ~ 3), -#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% reorder(TRTORD), -#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% reorder(TRTORD), -#' ANRLO = 30, -#' ANRHI = 75) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) %>% -#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), -#' paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) %>% -#' ungroup -#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] -#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']] -#' attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit' -#' attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit' -#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -#' ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')", -#' vars = list(arm_mapping = arm_mapping) -#' ), -#' check = FALSE -#' ), +#' data = data, #' modules = teal::modules( #' teal.goshawk::tm_g_gh_spaghettiplot( #' label = "Spaghetti Plot", diff --git a/man/tm_g_gh_boxplot.Rd b/man/tm_g_gh_boxplot.Rd index d6b1a847..60a0f540 100644 --- a/man/tm_g_gh_boxplot.Rd +++ b/man/tm_g_gh_boxplot.Rd @@ -106,121 +106,77 @@ summary table. \examples{ # Example using ADaM structure analysis dataset. - -library(dplyr) -library(nestcolor) - -# original ARM value = dose value -arm_mapping <- list( - "A: Drug X" = "150mg QD", - "B: Placebo" = "Placebo", - "C: Combination" = "Combination" -) - -set.seed(1) -ADSL <- goshawk::rADSL -ADLB <- goshawk::rADLB -var_labels <- lapply(ADLB, function(x) attributes(x)$label) -ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( - AVISIT == "SCREENING" ~ "SCR", - AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), - TRUE ~ as.character(NA) - ), - AVISITCDN = dplyr::case_when( - AVISITCD == "SCR" ~ -2, - AVISITCD == "BL" ~ 0, - grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), - TRUE ~ as.numeric(NA) - ), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == "ARM C" ~ 1, - ARMCD == "ARM B" ~ 2, - ARMCD == "ARM A" ~ 3 - ), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD), - ANRLO = 50, - ANRHI = 75 - ) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC - )) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC - )) \%>\% - ungroup() - -attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] -attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" -attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" - -# add LLOQ and ULOQ variables -ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +data <- teal_data() +data <- within(data, { + library(dplyr) + library(nestcolor) + + # original ARM value = dose value + arm_mapping <- list( + "A: Drug X" = "150mg QD", + "B: Placebo" = "Placebo", + "C: Combination" = "Combination" + ) + set.seed(1) + ADSL <- goshawk::rADSL + ADLB <- goshawk::rADLB + var_labels <- lapply(ADLB, function(x) attributes(x)$label) + ADLB <- ADLB \%>\% + dplyr::mutate( + AVISITCD = dplyr::case_when( + AVISIT == "SCREENING" ~ "SCR", + AVISIT == "BASELINE" ~ "BL", + grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + TRUE ~ as.character(NA) + ), + AVISITCDN = dplyr::case_when( + AVISITCD == "SCR" ~ -2, + AVISITCD == "BL" ~ 0, + grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), + TRUE ~ as.numeric(NA) + ), + AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), + TRTORD = dplyr::case_when( + ARMCD == "ARM C" ~ 1, + ARMCD == "ARM B" ~ 2, + ARMCD == "ARM A" ~ 3 + ), + ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), + ARM = factor(ARM) \%>\% reorder(TRTORD), + ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), + ACTARM = factor(ACTARM) \%>\% reorder(TRTORD), + ANRLO = 50, + ANRHI = 75 + ) \%>\% + dplyr::rowwise() \%>\% + dplyr::group_by(PARAMCD) \%>\% + dplyr::mutate(LBSTRESC = ifelse( + USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC + )) \%>\% + dplyr::mutate(LBSTRESC = ifelse( + USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC + )) \%>\% + ungroup() + + attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] + attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] + attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" + attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" + + # add LLOQ and ULOQ variables + ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) + ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +}) + +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames + +join_keys(data) <- default_cdisc_join_keys[datanames] app <- teal::init( - data = teal.data::cdisc_data( - adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = " - set.seed(1) - ADLB <- goshawk::rADLB - var_labels <- lapply(ADLB, function(x) attributes(x)$label) - ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == 'SCREENING' ~ 'SCR', - AVISIT == 'BASELINE' ~ 'BL', - grepl('WEEK', AVISIT) ~ paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), - TRUE ~ as.character(NA)), - AVISITCDN = dplyr::case_when( - AVISITCD == 'SCR' ~ -2, - AVISITCD == 'BL' ~ 0, - grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), - TRUE ~ as.numeric(NA)), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == 'ARM C' ~ 1, - ARMCD == 'ARM B' ~ 2, - ARMCD == 'ARM A' ~ 3), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD), - ANRLO = 50, - ANRHI = 75) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) \%>\% - ungroup() - attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] - attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']] - attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit' - attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit' - # add LLOQ and ULOQ variables - ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) - ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')", - vars = list(ADSL = adsl, arm_mapping = arm_mapping) - ), - check = FALSE # to shorten the example check = FALSE, in real scenarios use check = TRUE - ), + data = data, modules = teal::modules( teal.goshawk::tm_g_gh_boxplot( label = "Box Plot", diff --git a/man/tm_g_gh_correlationplot.Rd b/man/tm_g_gh_correlationplot.Rd index b7bd54f8..306f46e1 100644 --- a/man/tm_g_gh_correlationplot.Rd +++ b/man/tm_g_gh_correlationplot.Rd @@ -128,156 +128,95 @@ Scatter Plot Teal Module For Biomarker Analysis \examples{ # Example using ADaM structure analysis dataset. - -# original ARM value = dose value -arm_mapping <- list( - "A: Drug X" = "150mg QD", - "B: Placebo" = "Placebo", - "C: Combination" = "Combination" -) -color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") -# assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA" -shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) - -set.seed(1) -ADSL <- goshawk::rADSL -ADLB <- goshawk::rADLB -var_labels <- lapply(ADLB, function(x) attributes(x)$label) -ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == "SCREENING" ~ "SCR", - AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ - paste( - "W", - trimws( - substr( - AVISIT, - start = 6, - stop = stringr::str_locate(AVISIT, "DAY") - 1 +data <- teal_data() +data <- within(data, { + # original ARM value = dose value + arm_mapping <- list( + "A: Drug X" = "150mg QD", + "B: Placebo" = "Placebo", + "C: Combination" = "Combination" + ) + color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") + # assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA" + shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) + + set.seed(1) + ADSL <- goshawk::rADSL + ADLB <- goshawk::rADLB + var_labels <- lapply(ADLB, function(x) attributes(x)$label) + ADLB <- ADLB \%>\% + dplyr::mutate(AVISITCD = dplyr::case_when( + AVISIT == "SCREENING" ~ "SCR", + AVISIT == "BASELINE" ~ "BL", + grepl("WEEK", AVISIT) ~ + paste( + "W", + trimws( + substr( + AVISIT, + start = 6, + stop = stringr::str_locate(AVISIT, "DAY") - 1 + ) ) - ) - ), - TRUE ~ NA_character_ - )) \%>\% - dplyr::mutate(AVISITCDN = dplyr::case_when( - AVISITCD == "SCR" ~ -2, - AVISITCD == "BL" ~ 0, - grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), - TRUE ~ NA_real_ - )) \%>\% - # use ARMCD values to order treatment in visualization legend - dplyr::mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, - ifelse(grepl("B", ARMCD), 2, - ifelse(grepl("A", ARMCD), 3, NA) - ) - )) \%>\% - dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) \%>\% - dplyr::mutate(ARM = factor(ARM) \%>\% - reorder(TRTORD)) \%>\% - dplyr::mutate( - ANRHI = dplyr::case_when( - PARAMCD == "ALT" ~ 60, - PARAMCD == "CRP" ~ 70, - PARAMCD == "IGA" ~ 80, + ), + TRUE ~ NA_character_ + )) \%>\% + dplyr::mutate(AVISITCDN = dplyr::case_when( + AVISITCD == "SCR" ~ -2, + AVISITCD == "BL" ~ 0, + grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ NA_real_ - ), - ANRLO = dplyr::case_when( - PARAMCD == "ALT" ~ 20, - PARAMCD == "CRP" ~ 30, - PARAMCD == "IGA" ~ 40, - TRUE ~ NA_real_ - ) - ) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC - )) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC - )) \%>\% - ungroup() -attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" -attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" - -# add LLOQ and ULOQ variables -ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM") + )) \%>\% + # use ARMCD values to order treatment in visualization legend + dplyr::mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, + ifelse(grepl("B", ARMCD), 2, + ifelse(grepl("A", ARMCD), 3, NA) + ) + )) \%>\% + dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) \%>\% + dplyr::mutate(ARM = factor(ARM) \%>\% + reorder(TRTORD)) \%>\% + dplyr::mutate( + ANRHI = dplyr::case_when( + PARAMCD == "ALT" ~ 60, + PARAMCD == "CRP" ~ 70, + PARAMCD == "IGA" ~ 80, + TRUE ~ NA_real_ + ), + ANRLO = dplyr::case_when( + PARAMCD == "ALT" ~ 20, + PARAMCD == "CRP" ~ 30, + PARAMCD == "IGA" ~ 40, + TRUE ~ NA_real_ + ) + ) \%>\% + dplyr::rowwise() \%>\% + dplyr::group_by(PARAMCD) \%>\% + dplyr::mutate(LBSTRESC = ifelse( + USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC + )) \%>\% + dplyr::mutate(LBSTRESC = ifelse( + USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC + )) \%>\% + ungroup() + attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] + attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" + attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" + + # add LLOQ and ULOQ variables + ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB) + ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM") +}) + +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames + +join_keys(data) <- default_cdisc_join_keys[datanames] app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "set.seed(1) - ADLB <- goshawk::rADLB - var_labels <- lapply(ADLB, function(x) attributes(x)$label) - ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == 'SCREENING' ~ 'SCR', - AVISIT == 'BASELINE' ~ 'BL', - grepl('WEEK', AVISIT) ~ - paste( - 'W', - trimws( - substr( - AVISIT, - start = 6, - stop = stringr::str_locate(AVISIT, 'DAY') - 1 - ) - ) - ), - TRUE ~ NA_character_)) \%>\% - dplyr::mutate(AVISITCDN = dplyr::case_when( - AVISITCD == 'SCR' ~ -2, - AVISITCD == 'BL' ~ 0, - grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), - TRUE ~ NA_real_)) \%>\% - # use ARMCD values to order treatment in visualization legend - dplyr::mutate(TRTORD = ifelse(grepl('C', ARMCD), 1, - ifelse(grepl('B', ARMCD), 2, - ifelse(grepl('A', ARMCD), 3, NA)))) \%>\% - dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) \%>\% - dplyr::mutate(ARM = factor(ARM) \%>\% - reorder(TRTORD)) \%>\% - dplyr::mutate( - ANRHI = dplyr::case_when( - PARAMCD == 'ALT' ~ 60, - PARAMCD == 'CRP' ~ 70, - PARAMCD == 'IGA' ~ 80, - TRUE ~ NA_real_ - ), - ANRLO = dplyr::case_when( - PARAMCD == 'ALT' ~ 20, - PARAMCD == 'CRP' ~ 30, - PARAMCD == 'IGA' ~ 40, - TRUE ~ NA_real_ - )) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) \%>\% - dplyr::mutate(LBSTRESC = ifelse( - USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) \%>\% - ungroup() - attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] - attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit' - attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit' - - # add LLOQ and ULOQ variables - ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB) - ADLB <- left_join(ADLB, ADLB_LOQS, by = 'PARAM')", - vars = list(arm_mapping = arm_mapping) - ), - check = TRUE - ), + data = data, modules = teal::modules( teal.goshawk::tm_g_gh_correlationplot( label = "Correlation Plot", @@ -320,6 +259,7 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } \author{ Nick Paszty (npaszty) paszty.nicholas@gene.com diff --git a/man/tm_g_gh_density_distribution_plot.Rd b/man/tm_g_gh_density_distribution_plot.Rd index a9408a6b..a81ed9e8 100644 --- a/man/tm_g_gh_density_distribution_plot.Rd +++ b/man/tm_g_gh_density_distribution_plot.Rd @@ -84,82 +84,54 @@ None \examples{ # Example using ADaM structure analysis dataset. - -library(dplyr) - -# original ARM value = dose value -arm_mapping <- list( - "A: Drug X" = "150mg QD", - "B: Placebo" = "Placebo", - "C: Combination" = "Combination" -) -ADSL <- goshawk::rADSL -ADLB <- goshawk::rADLB -var_labels <- lapply(ADLB, function(x) attributes(x)$label) -ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( - AVISIT == "SCREENING" ~ "SCR", - AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), - TRUE ~ as.character(NA) - ), - AVISITCDN = dplyr::case_when( - AVISITCD == "SCR" ~ -2, - AVISITCD == "BL" ~ 0, - grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), - TRUE ~ as.numeric(NA) - ), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == "ARM C" ~ 1, - ARMCD == "ARM B" ~ 2, - ARMCD == "ARM A" ~ 3 - ), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD) +data <- teal_data() +data <- within(data, { + library(dplyr) + # original ARM value = dose value + arm_mapping <- list( + "A: Drug X" = "150mg QD", + "B: Placebo" = "Placebo", + "C: Combination" = "Combination" ) + ADSL <- goshawk::rADSL + ADLB <- goshawk::rADLB + var_labels <- lapply(ADLB, function(x) attributes(x)$label) + ADLB <- ADLB \%>\% + dplyr::mutate( + AVISITCD = dplyr::case_when( + AVISIT == "SCREENING" ~ "SCR", + AVISIT == "BASELINE" ~ "BL", + grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + TRUE ~ as.character(NA) + ), + AVISITCDN = dplyr::case_when( + AVISITCD == "SCR" ~ -2, + AVISITCD == "BL" ~ 0, + grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), + TRUE ~ as.numeric(NA) + ), + AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), + TRTORD = dplyr::case_when( + ARMCD == "ARM C" ~ 1, + ARMCD == "ARM B" ~ 2, + ARMCD == "ARM A" ~ 3 + ), + ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), + ARM = factor(ARM) \%>\% reorder(TRTORD), + ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), + ACTARM = factor(ACTARM) \%>\% reorder(TRTORD) + ) -attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] + attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] + attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +}) + +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "ADLB <- goshawk::rADLB - var_labels <- lapply(ADLB, function(x) attributes(x)$label) - ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == 'SCREENING' ~ 'SCR', - AVISIT == 'BASELINE' ~ 'BL', - grepl('WEEK', AVISIT) ~ - paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), - TRUE ~ as.character(NA)), - AVISITCDN = dplyr::case_when( - AVISITCD == 'SCR' ~ -2, - AVISITCD == 'BL' ~ 0, - grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), - TRUE ~ as.numeric(NA)), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == 'ARM C' ~ 1, - ARMCD == 'ARM B' ~ 2, - ARMCD == 'ARM A' ~ 3), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD)) - attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] - attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]", - vars = list(arm_mapping = arm_mapping) - ), - check = TRUE - ), + data = data, modules = teal::modules( teal.goshawk::tm_g_gh_density_distribution_plot( label = "Density Distribution Plot", @@ -187,6 +159,7 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } \author{ Nick Paszty (npaszty) paszty.nicholas@gene.com diff --git a/man/tm_g_gh_lineplot.Rd b/man/tm_g_gh_lineplot.Rd index 47404608..1c151288 100644 --- a/man/tm_g_gh_lineplot.Rd +++ b/man/tm_g_gh_lineplot.Rd @@ -122,82 +122,57 @@ This teal module renders the UI and calls the function that creates a line plot. \examples{ # Example using ADaM structure analysis dataset. +data <- teal_data() +data <- within(data, { + library(dplyr) + library(stringr) + library(nestcolor) + + # original ARM value = dose value + arm_mapping <- list( + "A: Drug X" = "150mg QD", + "B: Placebo" = "Placebo", + "C: Combination" = "Combination" + ) -library(dplyr) -library(stringr) -library(nestcolor) - -# original ARM value = dose value -arm_mapping <- list( - "A: Drug X" = "150mg QD", - "B: Placebo" = "Placebo", - "C: Combination" = "Combination" -) + ADSL <- goshawk::rADSL + ADLB <- goshawk::rADLB + var_labels <- lapply(ADLB, function(x) attributes(x)$label) + ADLB <- ADLB \%>\% + dplyr::mutate( + AVISITCD = dplyr::case_when( + AVISIT == "SCREENING" ~ "SCR", + AVISIT == "BASELINE" ~ "BL", + grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + TRUE ~ as.character(NA) + ), + AVISITCDN = dplyr::case_when( + AVISITCD == "SCR" ~ -2, + AVISITCD == "BL" ~ 0, + grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), + TRUE ~ as.numeric(NA) + ), + AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), + TRTORD = dplyr::case_when( + ARMCD == "ARM C" ~ 1, + ARMCD == "ARM B" ~ 2, + ARMCD == "ARM A" ~ 3 + ), + ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), + ARM = factor(ARM) \%>\% reorder(TRTORD), + ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), + ACTARM = factor(ACTARM) \%>\% reorder(TRTORD) + ) + attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] + attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +}) -ADSL <- goshawk::rADSL -ADLB <- goshawk::rADLB -var_labels <- lapply(ADLB, function(x) attributes(x)$label) -ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( - AVISIT == "SCREENING" ~ "SCR", - AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), - TRUE ~ as.character(NA) - ), - AVISITCDN = dplyr::case_when( - AVISITCD == "SCR" ~ -2, - AVISITCD == "BL" ~ 0, - grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), - TRUE ~ as.numeric(NA) - ), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == "ARM C" ~ 1, - ARMCD == "ARM B" ~ 2, - ARMCD == "ARM A" ~ 3 - ), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD) - ) -attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] app <- teal::init( - data = teal.data::cdisc_data( - adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset("ADLB", ADLB, - code = "ADLB <- goshawk::rADLB - var_labels <- lapply(ADLB, function(x) attributes(x)$label) - ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == 'SCREENING' ~ 'SCR', - AVISIT == 'BASELINE' ~ 'BL', - grepl('WEEK', AVISIT) ~ - paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), - TRUE ~ as.character(NA)), - AVISITCDN = dplyr::case_when( - AVISITCD == 'SCR' ~ -2, - AVISITCD == 'BL' ~ 0, - grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), - TRUE ~ as.numeric(NA)), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == 'ARM C' ~ 1, - ARMCD == 'ARM B' ~ 2, - ARMCD == 'ARM A' ~ 3), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD)) - attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] - attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]", - vars = list(ADSL = adsl, arm_mapping = arm_mapping) - ), - check = TRUE - ), + data = data, modules = teal::modules( teal.goshawk::tm_g_gh_lineplot( label = "Line Plot", @@ -217,6 +192,7 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } \author{ Wenyi Liu (luiw2) wenyi.liu@roche.com diff --git a/man/tm_g_gh_scatterplot.Rd b/man/tm_g_gh_scatterplot.Rd index bab1d6a7..19770aa5 100644 --- a/man/tm_g_gh_scatterplot.Rd +++ b/man/tm_g_gh_scatterplot.Rd @@ -86,81 +86,56 @@ into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} el instead. } \examples{ + # Example using ADaM structure analysis dataset. +data <- teal_data() +data <- within(data, { + # original ARM value = dose value + arm_mapping <- list( + "A: Drug X" = "150mg QD", + "B: Placebo" = "Placebo", + "C: Combination" = "Combination" + ) -# original ARM value = dose value -arm_mapping <- list( - "A: Drug X" = "150mg QD", - "B: Placebo" = "Placebo", - "C: Combination" = "Combination" -) + ADSL <- goshawk::rADSL + ADLB <- goshawk::rADLB + var_labels <- lapply(ADLB, function(x) attributes(x)$label) + ADLB <- ADLB \%>\% + dplyr::mutate( + AVISITCD = dplyr::case_when( + AVISIT == "SCREENING" ~ "SCR", + AVISIT == "BASELINE" ~ "BL", + grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + TRUE ~ as.character(NA) + ), + AVISITCDN = dplyr::case_when( + AVISITCD == "SCR" ~ -2, + AVISITCD == "BL" ~ 0, + grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), + TRUE ~ as.numeric(NA) + ), + AVISITCD = factor(AVISITCD) \%>\% stats::reorder(AVISITCDN), + TRTORD = dplyr::case_when( + ARMCD == "ARM C" ~ 1, + ARMCD == "ARM B" ~ 2, + ARMCD == "ARM A" ~ 3 + ), + ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), + ARM = factor(ARM) \%>\% stats::reorder(TRTORD), + ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), + ACTARM = factor(ACTARM) \%>\% stats::reorder(TRTORD) + ) + attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] + attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] +}) + +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] -ADSL <- goshawk::rADSL -ADLB <- goshawk::rADLB -var_labels <- lapply(ADLB, function(x) attributes(x)$label) -ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( - AVISIT == "SCREENING" ~ "SCR", - AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), - TRUE ~ as.character(NA) - ), - AVISITCDN = dplyr::case_when( - AVISITCD == "SCR" ~ -2, - AVISITCD == "BL" ~ 0, - grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), - TRUE ~ as.numeric(NA) - ), - AVISITCD = factor(AVISITCD) \%>\% stats::reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == "ARM C" ~ 1, - ARMCD == "ARM B" ~ 2, - ARMCD == "ARM A" ~ 3 - ), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% stats::reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% stats::reorder(TRTORD) - ) -attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] app <- teal::init( - data = teal.data::cdisc_data( - adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "ADLB <- goshawk::rADLB - var_labels <- lapply(ADLB, function(x) attributes(x)$label) - ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == 'SCREENING' ~ 'SCR', - AVISIT == 'BASELINE' ~ 'BL', - grepl('WEEK', AVISIT) ~ - paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), - TRUE ~ as.character(NA)), - AVISITCDN = dplyr::case_when( - AVISITCD == 'SCR' ~ -2, - AVISITCD == 'BL' ~ 0, - grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), - TRUE ~ as.numeric(NA)), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == 'ARM C' ~ 1, - ARMCD == 'ARM B' ~ 2, - ARMCD == 'ARM A' ~ 3), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD)) - attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] - attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]", - vars = list(ADSL = adsl, arm_mapping = arm_mapping) - ), - check = TRUE - ), + data = data, modules = teal::modules( teal.goshawk::tm_g_gh_scatterplot( label = "Scatter Plot", diff --git a/man/tm_g_gh_spaghettiplot.Rd b/man/tm_g_gh_spaghettiplot.Rd index 1538edbf..f5a72c83 100644 --- a/man/tm_g_gh_spaghettiplot.Rd +++ b/man/tm_g_gh_spaghettiplot.Rd @@ -126,113 +126,72 @@ that creates a spaghetti plot. \examples{ # Example using ADaM structure analysis dataset. - -library(dplyr) - -# original ARM value = dose value -arm_mapping <- list( - "A: Drug X" = "150mg QD", - "B: Placebo" = "Placebo", - "C: Combination" = "Combination" -) -set.seed(1) -ADSL <- goshawk::rADSL -ADLB <- goshawk::rADLB -var_labels <- lapply(ADLB, function(x) attributes(x)$label) -ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( - AVISIT == "SCREENING" ~ "SCR", - AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), - TRUE ~ as.character(NA) - ), - AVISITCDN = dplyr::case_when( - AVISITCD == "SCR" ~ -2, - AVISITCD == "BL" ~ 0, - grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), - TRUE ~ as.numeric(NA) - ), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == "ARM C" ~ 1, - ARMCD == "ARM B" ~ 2, - ARMCD == "ARM A" ~ 3 - ), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD), - ANRLO = 30, - ANRHI = 75 - ) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC - )) \%>\% - dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC - )) \%>\% - ungroup() -attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] -attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] -attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" -attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" - -# add LLOQ and ULOQ variables -ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) -ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +data <- teal_data() +data <- within(data, { + library(dplyr) + + # original ARM value = dose value + arm_mapping <- list( + "A: Drug X" = "150mg QD", + "B: Placebo" = "Placebo", + "C: Combination" = "Combination" + ) + set.seed(1) + ADSL <- goshawk::rADSL + ADLB <- goshawk::rADLB + var_labels <- lapply(ADLB, function(x) attributes(x)$label) + ADLB <- ADLB \%>\% + dplyr::mutate( + AVISITCD = dplyr::case_when( + AVISIT == "SCREENING" ~ "SCR", + AVISIT == "BASELINE" ~ "BL", + grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + TRUE ~ as.character(NA) + ), + AVISITCDN = dplyr::case_when( + AVISITCD == "SCR" ~ -2, + AVISITCD == "BL" ~ 0, + grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), + TRUE ~ as.numeric(NA) + ), + AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), + TRTORD = dplyr::case_when( + ARMCD == "ARM C" ~ 1, + ARMCD == "ARM B" ~ 2, + ARMCD == "ARM A" ~ 3 + ), + ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), + ARM = factor(ARM) \%>\% reorder(TRTORD), + ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), + ACTARM = factor(ACTARM) \%>\% reorder(TRTORD), + ANRLO = 30, + ANRHI = 75 + ) \%>\% + dplyr::rowwise() \%>\% + dplyr::group_by(PARAMCD) \%>\% + dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC + )) \%>\% + dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC + )) \%>\% + ungroup() + attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] + attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] + attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" + attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" + + # add LLOQ and ULOQ variables + ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) + ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +}) + +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "set.seed(1) - ADLB <- goshawk::rADLB - var_labels <- lapply(ADLB, function(x) attributes(x)$label) - ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( - AVISIT == 'SCREENING' ~ 'SCR', - AVISIT == 'BASELINE' ~ 'BL', - grepl('WEEK', AVISIT) ~ - paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')), - TRUE ~ as.character(NA)), - AVISITCDN = dplyr::case_when( - AVISITCD == 'SCR' ~ -2, - AVISITCD == 'BL' ~ 0, - grepl('W', AVISITCD) ~ as.numeric(gsub('[^0-9]*', '', AVISITCD)), - TRUE ~ as.numeric(NA)), - AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( - ARMCD == 'ARM C' ~ 1, - ARMCD == 'ARM B' ~ 2, - ARMCD == 'ARM A' ~ 3), - ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% reorder(TRTORD), - ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% reorder(TRTORD), - ANRLO = 30, - ANRHI = 75) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) \%>\% - dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), - paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) \%>\% - ungroup - attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']] - attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']] - attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit' - attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit' - ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB) - ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')", - vars = list(arm_mapping = arm_mapping) - ), - check = FALSE - ), + data = data, modules = teal::modules( teal.goshawk::tm_g_gh_spaghettiplot( label = "Spaghetti Plot", diff --git a/vignettes/teal-goshawk.Rmd b/vignettes/teal-goshawk.Rmd index 6132223d..56fd8e57 100644 --- a/vignettes/teal-goshawk.Rmd +++ b/vignettes/teal-goshawk.Rmd @@ -51,31 +51,34 @@ A simple application including the box plot module could look like this: library(teal.goshawk) library(nestcolor) -ADSL <- goshawk::rADSL %>% - mutate(TRTORD = case_when( - TRT01P == "A: Drug X" ~ 1, - TRT01P == "C: Combination" ~ 2, - TRT01P == "B: Placebo" ~ 3, - TRUE ~ as.numeric(NA) +data <- teal_data() +data <- within(data, { + ADSL <- goshawk::rADSL %>% + mutate(TRTORD = case_when( + TRT01P == "A: Drug X" ~ 1, + TRT01P == "C: Combination" ~ 2, + TRT01P == "B: Placebo" ~ 3, + TRUE ~ as.numeric(NA) ) - ) + ) + + ADLB <- goshawk::rADLB %>% + mutate(AVISITCD = AVISIT, + TRTORD = case_when( + TRT01P == "A: Drug X" ~ 1, + TRT01P == "C: Combination" ~ 2, + TRT01P == "B: Placebo" ~ 3, + TRUE ~ as.numeric(NA) + ) + ) +}) -ADLB <- goshawk::rADLB %>% - mutate(AVISITCD = AVISIT, - TRTORD = case_when( - TRT01P == "A: Drug X" ~ 1, - TRT01P == "C: Combination" ~ 2, - TRT01P == "B: Placebo" ~ 3, - TRUE ~ as.numeric(NA) - ) - ) +datanames <- c("ADSL", "ADLB") +datanames(data)<- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"), - teal.data::cdisc_dataset("ADLB", ADLB, code = "ADLB <- goshawk::rADLB"), - check = FALSE - ), + data = data, modules = list( tm_g_gh_boxplot( label = "Longitudinal Analysis",