From 5b30c028f4d8f509fc3cfdc4d14d114e1df8a89d Mon Sep 17 00:00:00 2001 From: Vedha Viyash <49812166+vedhav@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:31:10 +0530 Subject: [PATCH 1/2] Update docs to use the new `teal_data` instead of `TealData` (#597) Closes #591 and also use the new `join_keys` functions and methods part of the [teal.data PR #184](https://github.com/insightsengineering/teal.data/pull/184) --------- Co-authored-by: Vedha Viyash --- DESCRIPTION | 8 +- NEWS.md | 4 + R/tm_a_pca.R | 28 ++-- R/tm_a_regression.R | 18 ++- R/tm_data_table.R | 14 +- R/tm_file_viewer.R | 11 +- R/tm_front_page.R | 18 +-- R/tm_g_association.R | 21 +-- R/tm_g_bivariate.R | 24 ++-- R/tm_g_distribution.R | 32 +++-- R/tm_g_response.R | 21 +-- R/tm_g_scatterplot.R | 29 ++-- R/tm_g_scatterplotmatrix.R | 24 ++-- R/tm_missing_data.R | 22 +-- R/tm_outliers.R | 28 ++-- R/tm_t_crosstable.R | 20 +-- R/tm_variable_browser.R | 24 ++-- man/tm_a_pca.Rd | 24 ++-- man/tm_a_regression.Rd | 16 ++- man/tm_data_table.Rd | 14 +- man/tm_file_viewer.Rd | 11 +- man/tm_front_page.Rd | 18 +-- man/tm_g_association.Rd | 19 +-- man/tm_g_bivariate.Rd | 22 +-- man/tm_g_distribution.Rd | 32 +++-- man/tm_g_response.Rd | 19 +-- man/tm_g_scatterplot.Rd | 27 ++-- man/tm_g_scatterplotmatrix.Rd | 22 +-- man/tm_missing_data.Rd | 18 +-- man/tm_outliers.Rd | 24 ++-- man/tm_t_crosstable.Rd | 18 +-- man/tm_variable_browser.Rd | 16 ++- vignettes/teal-modules-general.Rmd | 45 ++++-- vignettes/using-association-plot.Rmd | 103 +++++++------- vignettes/using-bivariate-plot.Rmd | 186 ++++++++++++------------- vignettes/using-cross-table.Rmd | 73 ++++------ vignettes/using-data-table.Rmd | 19 +-- vignettes/using-outliers-module.Rmd | 46 +++--- vignettes/using-regression-plots.Rmd | 98 ++++++------- vignettes/using-response-plot.Rmd | 128 ++++++++--------- vignettes/using-scatterplot-matrix.Rmd | 70 ++++------ vignettes/using-scatterplot.Rmd | 120 ++++++++-------- 42 files changed, 795 insertions(+), 739 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b3826c6c1..e743c6ead 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ Depends: R (>= 3.6), shiny (>= 1.6.0), shinyTree, - teal (>= 0.14.0) + teal (>= 0.14.0.9019) Imports: checkmate (>= 2.1.0), dplyr (>= 1.0.5), @@ -39,8 +39,8 @@ Imports: teal.code (>= 0.4.0), teal.logger (>= 0.1.1), teal.reporter (>= 0.2.0), - teal.slice (>= 0.4.0), - teal.transform (>= 0.4.0), + teal.slice (>= 0.4.0.9023), + teal.transform (>= 0.4.0.9007), teal.widgets (>= 0.4.0), tern (>= 0.7.10), tibble (>= 2.0.0), @@ -65,7 +65,7 @@ Suggests: rlang (>= 1.0.0), rtables (>= 0.5.1), sparkline, - teal.data (>= 0.3.0), + teal.data (>= 0.3.0.9010), testthat (>= 3.0.4) VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 4ffd92fe2..96528763a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # teal.modules.general 0.2.16.9010 +### Enhancements + +* Updated the package docs and vignettes with the new way of specifying data for `teal::init()`. The `data` argument will accept a `teal_data` object + ### Miscellaneous * Specified minimal version of package dependencies. diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index cc4f5ebd8..692b32748 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -24,24 +24,25 @@ #' #' # ADSL example #' -#' library(nestcolor) -#' ADSL <- teal.modules.general::rADSL -#' +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL" -#' ), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_a_pca( #' "PCA", #' dat = teal.transform::data_extract_spec( #' dataname = "ADSL", #' select = teal.transform::select_spec( -#' choices = teal.transform::variable_choices(data = ADSL, c("BMRKR1", "AGE", "EOSDY")), +#' choices = teal.transform::variable_choices( +#' data = data[["ADSL"]], c("BMRKR1", "AGE", "EOSDY") +#' ), #' selected = c("BMRKR1", "AGE"), #' multiple = TRUE #' ), @@ -56,7 +57,6 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } -#' tm_a_pca <- function(label = "Principal Component Analysis", dat, plot_height = c(600, 200, 2000), @@ -257,7 +257,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl response[[i]]$select$choices <- var_labels(data[[response[[i]]$dataname]]()) response[[i]]$select$choices <- setdiff( response[[i]]$select$choices, - unlist(get_join_keys(data)$get(response[[i]]$dataname)) + unlist(teal.data::join_keys(data)[[response[[i]]$dataname]]) ) } @@ -323,7 +323,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl anl_merged_input <- teal.transform::merge_expression_srv( selector_list = selector_list, datasets = data, - join_keys = get_join_keys(data) + join_keys = teal.data::join_keys(data) ) anl_merged_q <- reactive({ diff --git a/R/tm_a_regression.R b/R/tm_a_regression.R index 8ddaaf523..775fbbca2 100644 --- a/R/tm_a_regression.R +++ b/R/tm_a_regression.R @@ -34,13 +34,17 @@ #' # Regression graphs from selected response variable (BMRKR1) and #' # selected regressors (AGE) #' -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_a_regression( #' label = "Regression", @@ -58,7 +62,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variables:", -#' choices = teal.transform::variable_choices(ADSL, c("AGE", "SEX", "RACE")), +#' choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")), #' selected = "AGE", #' multiple = TRUE, #' fixed = FALSE @@ -291,7 +295,7 @@ srv_a_regression <- function(id, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = selector_list, datasets = data, - join_keys = get_join_keys(data) + join_keys = teal.data::join_keys(data) ) regression_var <- reactive({ diff --git a/R/tm_data_table.R b/R/tm_data_table.R index 41c9b146f..6fbe64df5 100644 --- a/R/tm_data_table.R +++ b/R/tm_data_table.R @@ -25,13 +25,17 @@ #' @export #' @examples #' -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_data_table( #' variables_selected = list(ADSL = c("STUDYID", "USUBJID", "SUBJID", "SITEID", "AGE", "SEX")), diff --git a/R/tm_file_viewer.R b/R/tm_file_viewer.R index 8c2a175b4..deb5632a0 100644 --- a/R/tm_file_viewer.R +++ b/R/tm_file_viewer.R @@ -13,11 +13,14 @@ #' @export #' #' @examples -#' data <- data.frame(1) +#' data <- teal_data() +#' data <- within(data, { +#' data <- data.frame(1) +#' }) +#' datanames(data) <- c("data") +#' #' app <- teal::init( -#' data = teal_data( -#' dataset("data", data) -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_file_viewer( #' input_path = list( diff --git a/R/tm_front_page.R b/R/tm_front_page.R index e57d4444e..75616ae3d 100644 --- a/R/tm_front_page.R +++ b/R/tm_front_page.R @@ -17,6 +17,15 @@ #' @export #' @examples #' +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' #' table_1 <- data.frame(Info = c("A", "B"), Text = c("A", "B")) #' table_2 <- data.frame(`Column 1` = c("C", "D"), `Column 2` = c(5.5, 6.6), `Column 3` = c("A", "B")) #' table_3 <- data.frame(Info = c("E", "F"), Text = c("G", "H")) @@ -27,15 +36,8 @@ #' "Table 3" = table_3 #' ) #' -#' ADSL <- teal.modules.general::rADSL #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' teal.data::cdisc_dataset("ADSL", ADSL, -#' code = "ADSL <- teal.modules.general::rADSL", -#' metadata = list("Author" = "NEST team", "data_source" = "synthetic data") -#' ), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_front_page( #' header_text = c( diff --git a/R/tm_g_association.R b/R/tm_g_association.R index 36ee84d82..5907f4cda 100644 --- a/R/tm_g_association.R +++ b/R/tm_g_association.R @@ -25,14 +25,17 @@ #' @examples #' # Association plot of selected reference variable (SEX) #' # against other selected variables (BMRKR1) -#' library(nestcolor) -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_g_association( #' ref = teal.transform::data_extract_spec( @@ -40,7 +43,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2") #' ), #' selected = "RACE", @@ -52,7 +55,7 @@ #' select = teal.transform::select_spec( #' label = "Select variables:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2") #' ), #' selected = "BMRKR2", @@ -248,7 +251,7 @@ srv_tm_g_association <- function(id, anl_merged_input <- teal.transform::merge_expression_srv( datasets = data, selector_list = selector_list, - join_keys = get_join_keys(data) + join_keys = teal.data::join_keys(data) ) anl_merged_q <- reactive({ diff --git a/R/tm_g_bivariate.R b/R/tm_g_bivariate.R index 2acd0b487..444ad2733 100644 --- a/R/tm_g_bivariate.R +++ b/R/tm_g_bivariate.R @@ -45,20 +45,24 @@ #' #' @examples #' # Bivariate plot of selected variable (AGE) against selected (SEX) -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_g_bivariate( #' x = teal.transform::data_extract_spec( #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(ADSL), +#' choices = teal.transform::variable_choices(data[["ADSL"]]), #' selected = "AGE", #' fixed = FALSE #' ) @@ -67,7 +71,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(ADSL), +#' choices = teal.transform::variable_choices(data[["ADSL"]]), #' selected = "SEX", #' multiple = FALSE, #' fixed = FALSE @@ -77,7 +81,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(ADSL), +#' choices = teal.transform::variable_choices(data[["ADSL"]]), #' selected = "ARM", #' fixed = FALSE #' ) @@ -86,7 +90,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(ADSL), +#' choices = teal.transform::variable_choices(data[["ADSL"]]), #' selected = "COUNTRY", #' fixed = FALSE #' ) @@ -437,7 +441,7 @@ srv_g_bivariate <- function(id, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = selector_list, datasets = data, - join_keys = get_join_keys(data) + join_keys = teal.data::join_keys(data) ) anl_merged_q <- reactive({ diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index 9a055e955..9afa58d09 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -29,8 +29,15 @@ #' #' @examples #' # Example with non-clinical data +#' +#' data <- teal_data() +#' data <- within(data, { +#' iris <- iris +#' }) +#' datanames(data) <- c("iris") +#' #' app <- teal::init( -#' data = teal_data(dataset("iris", iris)), +#' data = data, #' modules = list( #' teal.modules.general::tm_g_distribution( #' dist_var = teal.transform::data_extract_spec( @@ -48,22 +55,27 @@ #' } #' #' # Example with clinical data -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' vars1 <- choices_selected(variable_choices(ADSL, c("ARM", "COUNTRY", "SEX")), selected = NULL) +#' vars1 <- choices_selected( +#' variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")), +#' selected = NULL +#' ) #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' teal.data::cdisc_dataset("ADSL", ADSL), -#' code = "ADSL <- teal.modules.general::rADSL", -#' check = FALSE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_g_distribution( #' dist_var = teal.transform::data_extract_spec( #' dataname = "ADSL", #' select = teal.transform::select_spec( -#' choices = teal.transform::variable_choices(ADSL, c("AGE", "BMRKR1")), +#' choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), #' selected = "BMRKR1", #' multiple = FALSE, #' fixed = FALSE @@ -435,7 +447,7 @@ srv_distribution <- function(id, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = selector_list, datasets = data, - join_keys = get_join_keys(data) + join_keys = teal.data::join_keys(data) ) anl_merged_q <- reactive({ diff --git a/R/tm_g_response.R b/R/tm_g_response.R index 57e1a9856..f3cd52c1d 100644 --- a/R/tm_g_response.R +++ b/R/tm_g_response.R @@ -26,15 +26,18 @@ #' @export #' @examples #' # Response plot with selected response (BMRKR1) and selected x variable (RACE) -#' library(nestcolor) #' -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_g_response( #' label = "Response Plots", @@ -42,7 +45,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(ADSL, c("BMRKR2", "COUNTRY")), +#' choices = teal.transform::variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), #' selected = "BMRKR2", #' multiple = FALSE, #' fixed = FALSE @@ -52,7 +55,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(ADSL, c("SEX", "RACE")), +#' choices = teal.transform::variable_choices(data[["ADSL"]], c("SEX", "RACE")), #' selected = "RACE", #' multiple = FALSE, #' fixed = FALSE @@ -272,7 +275,7 @@ srv_g_response <- function(id, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = selector_list, datasets = data, - join_keys = get_join_keys(data) + join_keys = teal.data::join_keys(data) ) anl_merged_q <- reactive({ diff --git a/R/tm_g_scatterplot.R b/R/tm_g_scatterplot.R index d728d4628..cdaea83fe 100644 --- a/R/tm_g_scatterplot.R +++ b/R/tm_g_scatterplot.R @@ -36,15 +36,18 @@ #' @export #' @examples #' # Scatterplot of variables from ADSL dataset -#' library(nestcolor) #' -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_g_scatterplot( #' label = "Scatterplot Choices", @@ -53,7 +56,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("AGE", "BMRKR1", "BMRKR2") #' ), #' selected = "AGE", @@ -66,7 +69,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("AGE", "BMRKR1", "BMRKR2") #' ), #' selected = "BMRKR1", @@ -79,7 +82,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") #' ), #' selected = NULL, @@ -92,7 +95,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") #' ), #' selected = "AGE", @@ -105,7 +108,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("BMRKR2", "RACE", "REGION1") #' ), #' selected = NULL, @@ -118,7 +121,7 @@ #' select = teal.transform::select_spec( #' label = "Select variable:", #' choices = teal.transform::variable_choices( -#' ADSL, +#' data[["ADSL"]], #' c("BMRKR2", "RACE", "REGION1") #' ), #' selected = NULL, @@ -468,7 +471,7 @@ srv_g_scatterplot <- function(id, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = selector_list, datasets = data, - join_keys = get_join_keys(data), + join_keys = teal.data::join_keys(data), merge_function = "dplyr::inner_join" ) diff --git a/R/tm_g_scatterplotmatrix.R b/R/tm_g_scatterplotmatrix.R index 80184fba8..85e43923a 100644 --- a/R/tm_g_scatterplotmatrix.R +++ b/R/tm_g_scatterplotmatrix.R @@ -20,15 +20,17 @@ #' @examples #' # Scatterplot matrix of variables from ADSL dataset #' -#' ADSL <- teal.modules.general::rADSL -#' ADRS <- teal.modules.general::rADRS +#' data <- teal_data() +#' data <- within(data, { +#' ADSL <- teal.modules.general::rADSL +#' ADRS <- teal.modules.general::rADRS +#' }) +#' datanames <- c("ADSL", "ADRS") +#' 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 <- teal.modules.general::rADSL"), -#' teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_g_scatterplotmatrix( #' label = "Scatterplot matrix", @@ -37,7 +39,7 @@ #' dataname = "ADSL", #' select = select_spec( #' label = "Select variables:", -#' choices = variable_choices(ADSL), +#' choices = variable_choices(data[["ADSL"]]), #' selected = c("AGE", "RACE", "SEX"), #' multiple = TRUE, #' ordered = TRUE, @@ -49,13 +51,13 @@ #' filter = teal.transform::filter_spec( #' label = "Select endpoints:", #' vars = c("PARAMCD", "AVISIT"), -#' choices = value_choices(ADRS, c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), +#' choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), #' selected = "INVET - END OF INDUCTION", #' multiple = TRUE #' ), #' select = select_spec( #' label = "Select variables:", -#' choices = variable_choices(ADRS), +#' choices = variable_choices(data[["ADRS"]]), #' selected = c("AGE", "AVAL", "ADY"), #' multiple = TRUE, #' ordered = TRUE, @@ -178,7 +180,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab anl_merged_input <- teal.transform::merge_expression_srv( datasets = data, - join_keys = get_join_keys(data), + join_keys = teal.data::join_keys(data), selector_list = selector_list ) diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index 205cf3a03..1931e2362 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -16,17 +16,19 @@ #' @export #' #' @examples -#' library(nestcolor) #' -#' ADSL <- teal.modules.general::rADSL -#' ADRS <- teal.modules.general::rADRS +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- teal.modules.general::rADSL +#' ADRS <- teal.modules.general::rADRS +#' }) +#' datanames <- c("ADSL", "ADRS") +#' 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 <- teal.modules.general::rADSL"), -#' teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_missing_data( #' ggplot2_args = list( @@ -354,7 +356,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par moduleServer(id, function(input, output, session) { prev_group_by_var <- reactiveVal("") data_r <- data[[dataname]] - data_keys <- reactive(get_join_keys(data)$get(dataname)[[dataname]]) + data_keys <- reactive(unlist(teal.data::join_keys(data)[[dataname]])) iv_r <- reactive({ iv <- shinyvalidate::InputValidator$new() @@ -393,7 +395,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par data_parent_keys <- reactive({ if (length(parent_dataname) > 0 && parent_dataname %in% names(data)) { - keys <- get_join_keys(data)$get(dataname) + keys <- teal.data::join_keys(data)[[dataname]] if (parent_dataname %in% names(keys)) { keys[[parent_dataname]] } else { diff --git a/R/tm_outliers.R b/R/tm_outliers.R index f30ac883f..71341c563 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -17,16 +17,19 @@ #' #' @examples #' -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' datanames(data) <- datanames +#' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' fact_vars_adsl <- names(Filter(isTRUE, sapply(ADSL, is.factor))) -#' vars <- choices_selected(variable_choices(ADSL, fact_vars_adsl)) +#' fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) +#' vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) #' #' app <- teal::init( -#' data = teal.data::cdisc_data( -#' teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_outliers( #' outlier_var = list( @@ -34,7 +37,7 @@ #' dataname = "ADSL", #' select = select_spec( #' label = "Select variable:", -#' choices = variable_choices(ADSL, c("AGE", "BMRKR1")), +#' choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), #' selected = "AGE", #' multiple = FALSE, #' fixed = FALSE @@ -46,8 +49,8 @@ #' dataname = "ADSL", #' filter = teal.transform::filter_spec( #' vars = vars, -#' choices = value_choices(ADSL, vars$selected), -#' selected = value_choices(ADSL, vars$selected), +#' choices = value_choices(data[["ADSL"]], vars$selected), +#' selected = value_choices(data[["ADSL"]], vars$selected), #' multiple = TRUE #' ) #' ) @@ -63,7 +66,6 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } -#' tm_outliers <- function(label = "Outliers Module", outlier_var, categorical_var = NULL, @@ -291,7 +293,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = reactive_select_input, datasets = data, - join_keys = get_join_keys(data), + join_keys = teal.data::join_keys(data), merge_function = "dplyr::inner_join" ) @@ -474,7 +476,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, }, env = list( dataname = as.name(dataname_first), - join_keys = as.character(get_join_keys(data)$get(dataname_first)[[dataname_first]]) + join_keys = as.character(teal.data::join_keys(data)[dataname_first, dataname_first]) ) ) ) diff --git a/R/tm_t_crosstable.R b/R/tm_t_crosstable.R index a31d68f3e..f4efb3169 100644 --- a/R/tm_t_crosstable.R +++ b/R/tm_t_crosstable.R @@ -23,13 +23,16 @@ #' @examples #' # Percentage cross table of variables from ADSL dataset #' -#' ADSL <- teal.modules.general::rADSL +#' data <- teal_data() +#' data <- within(data, { +#' ADSL <- teal.modules.general::rADSL +#' }) +#' datanames <- c("ADSL") +#' 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 <- teal.modules.general::rADSL"), -#' check = TRUE -#' ), +#' data = data, #' modules = teal::modules( #' teal.modules.general::tm_t_crosstable( #' label = "Cross Table", @@ -37,7 +40,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = variable_choices(ADSL, subset = function(data) { +#' choices = variable_choices(data[["ADSL"]], subset = function(data) { #' idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt")) #' return(names(data)[idx]) #' }), @@ -51,7 +54,7 @@ #' dataname = "ADSL", #' select = teal.transform::select_spec( #' label = "Select variable:", -#' choices = variable_choices(ADSL, subset = function(data) { +#' choices = variable_choices(data[["ADSL"]], subset = function(data) { #' idx <- vapply(data, is.factor, logical(1)) #' return(names(data)[idx]) #' }), @@ -69,7 +72,6 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } -#' tm_t_crosstable <- function(label = "Cross Table", x, y, @@ -213,7 +215,7 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, anl_merged_input <- teal.transform::merge_expression_srv( datasets = data, - join_keys = get_join_keys(data), + join_keys = teal.data::join_keys(data), selector_list = selector_list, merge_function = merge_function ) diff --git a/R/tm_variable_browser.R b/R/tm_variable_browser.R index c9887d36f..c4b7a19f8 100644 --- a/R/tm_variable_browser.R +++ b/R/tm_variable_browser.R @@ -31,15 +31,17 @@ #' #' @examples #' -#' ADSL <- teal.modules.general::rADSL -#' ADTTE <- teal.modules.general::rADTTE +#' data <- teal_data() +#' data <- within(data, { +#' ADSL <- teal.modules.general::rADSL +#' ADTTE <- teal.modules.general::rADTTE +#' }) +#' datanames <- c("ADSL", "ADTTE") +#' 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 <- teal.modules.general::rADSL"), -#' teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), -#' check = TRUE -#' ), +#' data = data, #' modules( #' teal.modules.general::tm_variable_browser( #' label = "Variable browser", @@ -1147,9 +1149,9 @@ render_tab_header <- function(dataset_name, output, data) { dataset_ui_id <- paste0("dataset_summary_", dataset_name) output[[dataset_ui_id]] <- renderText({ df <- data[[dataset_name]]() - join_keys <- get_join_keys(data) + join_keys <- join_keys(data) if (!is.null(join_keys)) { - key <- get_join_keys(data)$get(dataset_name)[[dataset_name]] + key <- join_keys(data)[dataset_name, dataset_name] } else { key <- NULL } @@ -1220,9 +1222,9 @@ render_tab_table <- function(dataset_name, parent_dataname, output, data, input, # get icons proper for the data types icons <- stats::setNames(teal.slice:::variable_types(df), colnames(df)) - join_keys <- get_join_keys(data) + join_keys <- join_keys(data) if (!is.null(join_keys)) { - icons[intersect(join_keys$get(dataset_name)[[dataset_name]], colnames(df))] <- "primary_key" + icons[intersect(join_keys[dataset_name, dataset_name], colnames(df))] <- "primary_key" } icons <- variable_type_icons(icons) diff --git a/man/tm_a_pca.Rd b/man/tm_a_pca.Rd index 0ea400fab..d0e4eb8ab 100644 --- a/man/tm_a_pca.Rd +++ b/man/tm_a_pca.Rd @@ -73,24 +73,25 @@ Principal component analysis module # ADSL example -library(nestcolor) -ADSL <- teal.modules.general::rADSL - +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL" - ), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_a_pca( "PCA", dat = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( - choices = teal.transform::variable_choices(data = ADSL, c("BMRKR1", "AGE", "EOSDY")), + choices = teal.transform::variable_choices( + data = data[["ADSL"]], c("BMRKR1", "AGE", "EOSDY") + ), selected = c("BMRKR1", "AGE"), multiple = TRUE ), @@ -105,5 +106,4 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } - } diff --git a/man/tm_a_regression.Rd b/man/tm_a_regression.Rd index 96c56ffc8..028978d7d 100644 --- a/man/tm_a_regression.Rd +++ b/man/tm_a_regression.Rd @@ -87,13 +87,17 @@ For more examples, please see the vignette "Using regression plots" via # Regression graphs from selected response variable (BMRKR1) and # selected regressors (AGE) -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_a_regression( label = "Regression", @@ -111,7 +115,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variables:", - choices = teal.transform::variable_choices(ADSL, c("AGE", "SEX", "RACE")), + choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")), selected = "AGE", multiple = TRUE, fixed = FALSE diff --git a/man/tm_data_table.Rd b/man/tm_data_table.Rd index 06bdc9249..c0cb56c50 100644 --- a/man/tm_data_table.Rd +++ b/man/tm_data_table.Rd @@ -54,13 +54,17 @@ Note though that sorting of numeric columns with \code{NA}/\code{Inf} will be le } \examples{ -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_data_table( variables_selected = list(ADSL = c("STUDYID", "USUBJID", "SUBJID", "SITEID", "AGE", "SEX")), diff --git a/man/tm_file_viewer.Rd b/man/tm_file_viewer.Rd index 4e1a340de..db3cffb1f 100644 --- a/man/tm_file_viewer.Rd +++ b/man/tm_file_viewer.Rd @@ -23,11 +23,14 @@ Supported formats include text formats, \code{PDF}, \code{PNG}, \code{APNG}, \code{JPEG}, \code{SVG}, \code{WEBP}, \code{GIF} and \code{BMP}. } \examples{ -data <- data.frame(1) +data <- teal_data() +data <- within(data, { + data <- data.frame(1) +}) +datanames(data) <- c("data") + app <- teal::init( - data = teal_data( - dataset("data", data) - ), + data = data, modules = teal::modules( teal.modules.general::tm_file_viewer( input_path = list( diff --git a/man/tm_front_page.Rd b/man/tm_front_page.Rd index 387b05ea9..0a12da77e 100644 --- a/man/tm_front_page.Rd +++ b/man/tm_front_page.Rd @@ -40,6 +40,15 @@ This \code{teal} module creates a simple front page for \code{teal} applications } \examples{ +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] + table_1 <- data.frame(Info = c("A", "B"), Text = c("A", "B")) table_2 <- data.frame(`Column 1` = c("C", "D"), `Column 2` = c(5.5, 6.6), `Column 3` = c("A", "B")) table_3 <- data.frame(Info = c("E", "F"), Text = c("G", "H")) @@ -50,15 +59,8 @@ table_input <- list( "Table 3" = table_3 ) -ADSL <- teal.modules.general::rADSL app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, - code = "ADSL <- teal.modules.general::rADSL", - metadata = list("Author" = "NEST team", "data_source" = "synthetic data") - ), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_front_page( header_text = c( diff --git a/man/tm_g_association.Rd b/man/tm_g_association.Rd index 483645824..96a8f31a8 100644 --- a/man/tm_g_association.Rd +++ b/man/tm_g_association.Rd @@ -71,14 +71,17 @@ For more examples, please see the vignette "Using association plot" via \examples{ # Association plot of selected reference variable (SEX) # against other selected variables (BMRKR1) -library(nestcolor) -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_g_association( ref = teal.transform::data_extract_spec( @@ -86,7 +89,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2") ), selected = "RACE", @@ -98,7 +101,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variables:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2") ), selected = "BMRKR2", diff --git a/man/tm_g_bivariate.Rd b/man/tm_g_bivariate.Rd index aa978a0aa..cdcd38fb3 100644 --- a/man/tm_g_bivariate.Rd +++ b/man/tm_g_bivariate.Rd @@ -113,20 +113,24 @@ For more examples, please see the vignette "Using bivariate plot" via } \examples{ # Bivariate plot of selected variable (AGE) against selected (SEX) -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_g_bivariate( x = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(ADSL), + choices = teal.transform::variable_choices(data[["ADSL"]]), selected = "AGE", fixed = FALSE ) @@ -135,7 +139,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(ADSL), + choices = teal.transform::variable_choices(data[["ADSL"]]), selected = "SEX", multiple = FALSE, fixed = FALSE @@ -145,7 +149,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(ADSL), + choices = teal.transform::variable_choices(data[["ADSL"]]), selected = "ARM", fixed = FALSE ) @@ -154,7 +158,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(ADSL), + choices = teal.transform::variable_choices(data[["ADSL"]]), selected = "COUNTRY", fixed = FALSE ) diff --git a/man/tm_g_distribution.Rd b/man/tm_g_distribution.Rd index eb23aa033..edd47d618 100644 --- a/man/tm_g_distribution.Rd +++ b/man/tm_g_distribution.Rd @@ -73,8 +73,15 @@ Module to analyze and explore univariate variable distribution } \examples{ # Example with non-clinical data + +data <- teal_data() +data <- within(data, { + iris <- iris +}) +datanames(data) <- c("iris") + app <- teal::init( - data = teal_data(dataset("iris", iris)), + data = data, modules = list( teal.modules.general::tm_g_distribution( dist_var = teal.transform::data_extract_spec( @@ -92,22 +99,27 @@ if (interactive()) { } # Example with clinical data -ADSL <- teal.modules.general::rADSL - -vars1 <- choices_selected(variable_choices(ADSL, c("ARM", "COUNTRY", "SEX")), selected = NULL) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] + +vars1 <- choices_selected( + variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")), + selected = NULL +) app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL), - code = "ADSL <- teal.modules.general::rADSL", - check = FALSE - ), + data = data, modules = teal::modules( teal.modules.general::tm_g_distribution( dist_var = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( - choices = teal.transform::variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE diff --git a/man/tm_g_response.Rd b/man/tm_g_response.Rd index e52736830..ae16fde07 100644 --- a/man/tm_g_response.Rd +++ b/man/tm_g_response.Rd @@ -85,15 +85,18 @@ For more examples, please see the vignette "Using response plot" via } \examples{ # Response plot with selected response (BMRKR1) and selected x variable (RACE) -library(nestcolor) -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_g_response( label = "Response Plots", @@ -101,7 +104,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(ADSL, c("BMRKR2", "COUNTRY")), + choices = teal.transform::variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), selected = "BMRKR2", multiple = FALSE, fixed = FALSE @@ -111,7 +114,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(ADSL, c("SEX", "RACE")), + choices = teal.transform::variable_choices(data[["ADSL"]], c("SEX", "RACE")), selected = "RACE", multiple = FALSE, fixed = FALSE diff --git a/man/tm_g_scatterplot.Rd b/man/tm_g_scatterplot.Rd index a72b3b504..46a0f8170 100644 --- a/man/tm_g_scatterplot.Rd +++ b/man/tm_g_scatterplot.Rd @@ -99,15 +99,18 @@ For more examples, please see the vignette "Using scatterplot" via } \examples{ # Scatterplot of variables from ADSL dataset -library(nestcolor) -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_g_scatterplot( label = "Scatterplot Choices", @@ -116,7 +119,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2") ), selected = "AGE", @@ -129,7 +132,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2") ), selected = "BMRKR1", @@ -142,7 +145,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") ), selected = NULL, @@ -155,7 +158,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") ), selected = "AGE", @@ -168,7 +171,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("BMRKR2", "RACE", "REGION1") ), selected = NULL, @@ -181,7 +184,7 @@ app <- teal::init( select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( - ADSL, + data[["ADSL"]], c("BMRKR2", "RACE", "REGION1") ), selected = NULL, diff --git a/man/tm_g_scatterplotmatrix.Rd b/man/tm_g_scatterplotmatrix.Rd index 09318d873..a43190fa5 100644 --- a/man/tm_g_scatterplotmatrix.Rd +++ b/man/tm_g_scatterplotmatrix.Rd @@ -45,15 +45,17 @@ For more examples, please see the vignette "Using scatterplot matrix" via \examples{ # Scatterplot matrix of variables from ADSL dataset -ADSL <- teal.modules.general::rADSL -ADRS <- teal.modules.general::rADRS +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADRS <- teal.modules.general::rADRS +}) +datanames <- c("ADSL", "ADRS") +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 <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_g_scatterplotmatrix( label = "Scatterplot matrix", @@ -62,7 +64,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = c("AGE", "RACE", "SEX"), multiple = TRUE, ordered = TRUE, @@ -74,13 +76,13 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoints:", vars = c("PARAMCD", "AVISIT"), - choices = value_choices(ADRS, c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), + choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), selected = "INVET - END OF INDUCTION", multiple = TRUE ), select = select_spec( label = "Select variables:", - choices = variable_choices(ADRS), + choices = variable_choices(data[["ADRS"]]), selected = c("AGE", "AVAL", "ADY"), multiple = TRUE, ordered = TRUE, diff --git a/man/tm_missing_data.Rd b/man/tm_missing_data.Rd index c2a534e1b..043fce15e 100644 --- a/man/tm_missing_data.Rd +++ b/man/tm_missing_data.Rd @@ -53,17 +53,19 @@ into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} el Present analysis of missing observations and patients. } \examples{ -library(nestcolor) -ADSL <- teal.modules.general::rADSL -ADRS <- teal.modules.general::rADRS +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- teal.modules.general::rADSL + ADRS <- teal.modules.general::rADRS +}) +datanames <- c("ADSL", "ADRS") +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 <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_missing_data( ggplot2_args = list( diff --git a/man/tm_outliers.Rd b/man/tm_outliers.Rd index ec83f6d83..a3d013200 100644 --- a/man/tm_outliers.Rd +++ b/man/tm_outliers.Rd @@ -56,16 +56,19 @@ Module to analyze and identify outliers using different methods } \examples{ -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] -fact_vars_adsl <- names(Filter(isTRUE, sapply(ADSL, is.factor))) -vars <- choices_selected(variable_choices(ADSL, fact_vars_adsl)) +fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) +vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_outliers( outlier_var = list( @@ -73,7 +76,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "AGE", multiple = FALSE, fixed = FALSE @@ -85,8 +88,8 @@ app <- teal::init( dataname = "ADSL", filter = teal.transform::filter_spec( vars = vars, - choices = value_choices(ADSL, vars$selected), - selected = value_choices(ADSL, vars$selected), + choices = value_choices(data[["ADSL"]], vars$selected), + selected = value_choices(data[["ADSL"]], vars$selected), multiple = TRUE ) ) @@ -102,5 +105,4 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } - } diff --git a/man/tm_t_crosstable.Rd b/man/tm_t_crosstable.Rd index bff1b386a..668380fa5 100644 --- a/man/tm_t_crosstable.Rd +++ b/man/tm_t_crosstable.Rd @@ -55,13 +55,16 @@ For more examples, please see the vignette "Using cross table" via \examples{ # Percentage cross table of variables from ADSL dataset -ADSL <- teal.modules.general::rADSL +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL +}) +datanames <- c("ADSL") +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 <- teal.modules.general::rADSL"), - check = TRUE - ), + data = data, modules = teal::modules( teal.modules.general::tm_t_crosstable( label = "Cross Table", @@ -69,7 +72,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = variable_choices(ADSL, subset = function(data) { + choices = variable_choices(data[["ADSL"]], subset = function(data) { idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt")) return(names(data)[idx]) }), @@ -83,7 +86,7 @@ app <- teal::init( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", - choices = variable_choices(ADSL, subset = function(data) { + choices = variable_choices(data[["ADSL"]], subset = function(data) { idx <- vapply(data, is.factor, logical(1)) return(names(data)[idx]) }), @@ -101,5 +104,4 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } - } diff --git a/man/tm_variable_browser.Rd b/man/tm_variable_browser.Rd index bfb8893a4..1d5135639 100644 --- a/man/tm_variable_browser.Rd +++ b/man/tm_variable_browser.Rd @@ -56,15 +56,17 @@ then the default is categorical, otherwise it is numeric). } \examples{ -ADSL <- teal.modules.general::rADSL -ADTTE <- teal.modules.general::rADTTE +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADTTE <- teal.modules.general::rADTTE +}) +datanames <- c("ADSL", "ADTTE") +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 <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - check = TRUE - ), + data = data, modules( teal.modules.general::tm_variable_browser( label = "Variable browser", diff --git a/vignettes/teal-modules-general.Rmd b/vignettes/teal-modules-general.Rmd index 63ba8ce21..588639320 100644 --- a/vignettes/teal-modules-general.Rmd +++ b/vignettes/teal-modules-general.Rmd @@ -43,15 +43,19 @@ A simple application including a `tm_variable_browser` module could look like th ```{r, message = FALSE, results = "hide"} library(teal.modules.general) -ADSL <- teal.modules.general::rADSL # nolint -ADTTE <- teal.modules.general::rADTTE # nolint +# nolint start +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADTTE <- teal.modules.general::rADTTE +}) +datanames <- c("ADSL", "ADTTE") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] +# nolint end app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", x = ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADTTE", x = ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - check = TRUE - ), + data = data, modules = teal::modules( tm_variable_browser( label = "Variable browser", @@ -72,10 +76,27 @@ Let's break the above app into pieces: library(teal.modules.general) ``` The line mentioned above imports the library required for this example and loads data from within that library. + +Now, we are building a `teal_data` object that will serve as the source of data for the teal app. +`teal_data` not only encapsulates the data for the app, but it also houses the code required to create the data to maintain reproducibility. +To do this, we create an empty `teal_data` object and evaluate code to produce the data within the `teal_data` object, +so both the code and data are stored together. + +Following this, we set the `datanames` and `join_keys`. + ```r -ADSL <- teal.modules.general::rADSL -ADAE <- teal.modules.general::rADAE +# nolint start +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADTTE <- teal.modules.general::rADTTE +}) +datanames <- c("ADSL", "ADTTE") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] +# nolint end ``` + There is no need to load `teal` as `teal.modules.general` already depends on it. In the next step, we use `teal` to create `shiny` `ui` and `server` functions so we can launch using `shiny`. The `data` @@ -84,11 +105,7 @@ argument indicates the modules included in the application. Here, we include onl ```{r, results = "hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", x = ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADTTE", x = ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - check = TRUE # to check if the code executes to the data provided, x, i.e. ADSL and ADTTE - ), + data = data, modules = teal::modules( tm_variable_browser( # module name to display in the GUI diff --git a/vignettes/using-association-plot.Rmd b/vignettes/using-association-plot.Rmd index fd2b25e16..8921c79d1 100644 --- a/vignettes/using-association-plot.Rmd +++ b/vignettes/using-association-plot.Rmd @@ -61,30 +61,33 @@ itself will be constructed by multiple calls of `tm_g_association` using differe combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} +# nolint start +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADSL2 <- ADSL %>% + mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) + ADRS <- teal.modules.general::rADRS + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB") +datanames(data) <- datanames +jk <- default_cdisc_join_keys[datanames] +jk_adsl2 <- jk +names(jk_adsl2)[names(jk_adsl2) == "ADSL"] <- "ADSL2" +jk <- c(jk, jk_adsl2) +jk["ADSL2", "ADSL"] <- c("USUBJID", "STUDYID") + +# nolint end + app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset( - "ADSL2", - ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( # tm_g_association ---- modules( @@ -95,7 +98,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = "AGE", fixed = FALSE ) @@ -104,7 +107,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = "BMRKR1", multiple = TRUE, fixed = FALSE @@ -117,7 +120,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "SEX", "STRATA1", "RACE")), + choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "STRATA1", "RACE")), selected = "STRATA1", multiple = FALSE, fixed = FALSE @@ -127,7 +130,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL2, c("AGE", "SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL2"]], c("AGE", "SEX", "RACE", "COUNTRY")), selected = c("AGE", "COUNTRY", "RACE"), multiple = TRUE, fixed = FALSE @@ -140,7 +143,7 @@ app <- teal::init( dataname = "ADTTE", select = select_spec( label = "Select variables:", - choices = variable_choices(ADTTE), + choices = variable_choices(data[["ADTTE"]]), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -148,7 +151,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoint:", vars = "PARAMCD", - choices = value_choices(ADTTE, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"), selected = c("PFS", "EFS"), multiple = TRUE ) @@ -158,7 +161,7 @@ app <- teal::init( reshape = TRUE, select = select_spec( label = "Select variable:", - choices = variable_choices(ADRS, c("AVALC", "BMRKR1", "BMRKR2", "ARM")), + choices = variable_choices(data[["ADRS"]], c("AVALC", "BMRKR1", "BMRKR2", "ARM")), selected = "AVALC", multiple = TRUE, fixed = FALSE @@ -167,14 +170,14 @@ app <- teal::init( filter_spec( label = "Select endpoints:", vars = "PARAMCD", - choices = value_choices(ADRS, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADRS"]], "PARAMCD", "PARAM"), selected = "BESRSPI", multiple = TRUE ), filter_spec( label = "Select endpoints:", vars = "AVISIT", - choices = levels(ADRS$AVISIT), + choices = levels(data[["ADRS"]]$AVISIT), selected = "SCREENING", multiple = TRUE ) @@ -186,7 +189,7 @@ app <- teal::init( ref = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVAL", "AVALC")), + choices = variable_choices(data[["ADRS"]], c("AVAL", "AVALC")), selected = "AVALC", multiple = FALSE, fixed = FALSE, @@ -195,15 +198,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADRS, "PARAMCD", "PARAM"), - selected = levels(ADRS$PARAMCD), + choices = value_choices(data[["ADRS"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADRS"]]$PARAMCD), multiple = TRUE, label = "Select response" ), filter_spec( vars = "AVISIT", - choices = levels(ADRS$AVISIT), - selected = levels(ADRS$AVISIT), + choices = levels(data[["ADRS"]]$AVISIT), + selected = levels(data[["ADRS"]]$AVISIT), multiple = TRUE, label = "Select visit:" ) @@ -212,7 +215,7 @@ app <- teal::init( vars = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "AGE", "RACE", "COUNTRY", "BMRKR1", "STRATA1", "ARM")), + choices = variable_choices(data[["ADSL"]], c("SEX", "AGE", "RACE", "COUNTRY", "BMRKR1", "STRATA1", "ARM")), selected = "AGE", multiple = TRUE, fixed = FALSE, @@ -225,7 +228,7 @@ app <- teal::init( ref = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS), + choices = variable_choices(data[["ADRS"]]), selected = "AVALC", multiple = FALSE, fixed = FALSE, @@ -235,7 +238,7 @@ app <- teal::init( vars = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS), + choices = variable_choices(data[["ADRS"]]), selected = "PARAMCD", multiple = TRUE, fixed = FALSE, @@ -250,21 +253,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("AVAL", "CHG2", "PCHG2")), + choices = variable_choices(data[["ADLB"]], c("AVAL", "CHG2", "PCHG2")), selected = "AVAL", multiple = FALSE ) @@ -274,21 +277,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select labs:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB), + choices = variable_choices(data[["ADLB"]]), selected = "STRATA1", multiple = TRUE ) diff --git a/vignettes/using-bivariate-plot.Rmd b/vignettes/using-bivariate-plot.Rmd index 0be71d829..ed09e6c78 100644 --- a/vignettes/using-bivariate-plot.Rmd +++ b/vignettes/using-bivariate-plot.Rmd @@ -42,17 +42,27 @@ Inside this app 5 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) -ADRS <- teal.modules.general::rADRS -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ "N", - CHG > 1 ~ "P", - TRUE ~ "-" - ))) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADSL2 <- teal.modules.general::rADSL %>% + mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) + ADRS <- teal.modules.general::rADRS + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB") +datanames(data) <- datanames +jk <- default_cdisc_join_keys[datanames] +jk_adsl2 <- jk +names(jk_adsl2)[names(jk_adsl2) == "ADSL"] <- "ADSL2" +jk <- c(jk, jk_adsl2) +jk["ADSL2", "ADSL"] <- c("USUBJID", "STUDYID") # nolint end ``` @@ -65,29 +75,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset( - "ADSL2", - ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( # tm_g_bivariate ------ modules( @@ -98,7 +86,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = "BMRKR1", fixed = FALSE ) @@ -107,7 +95,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = "SEX", multiple = FALSE, fixed = FALSE @@ -117,7 +105,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = NULL, multiple = FALSE, fixed = FALSE @@ -127,7 +115,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = NULL, multiple = FALSE, fixed = FALSE @@ -140,7 +128,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("BMRKR1", "AGE", "SEX", "STRATA1", "RACE")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "AGE", "SEX", "STRATA1", "RACE")), selected = c("BMRKR1"), multiple = FALSE ) @@ -149,7 +137,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL2, c("COUNTRY", "AGE", "RACE")), + choices = variable_choices(data[["ADSL2"]], c("COUNTRY", "AGE", "RACE")), selected = "RACE", multiple = FALSE ) @@ -158,7 +146,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = NULL, multiple = FALSE, fixed = FALSE @@ -168,7 +156,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL2), + choices = variable_choices(data[["ADSL2"]]), selected = NULL, multiple = FALSE, fixed = FALSE @@ -182,12 +170,12 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoints:", vars = c("PARAMCD", "AVISIT"), - choices = value_choices(ADRS, c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), + choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), selected = "OVRINV - END OF INDUCTION", multiple = TRUE ), select = select_spec( - choices = variable_choices(ADRS, c("AVALC", "AVAL")), + choices = variable_choices(data[["ADRS"]], c("AVALC", "AVAL")), selected = "AVALC", multiple = FALSE ) @@ -196,7 +184,7 @@ app <- teal::init( dataname = "ADTTE", select = select_spec( label = "Select variable:", - choices = variable_choices(ADTTE, c("AVAL", "CNSR")), + choices = variable_choices(data[["ADTTE"]], c("AVAL", "CNSR")), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -204,7 +192,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoint:", vars = c("PARAMCD"), - choices = value_choices(ADTTE, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"), selected = "OS", multiple = FALSE ) @@ -214,13 +202,13 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoints:", vars = c("PARAMCD", "AVISIT"), - choices = value_choices(ADRS, c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), + choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), selected = "OVRINV - SCREENING", multiple = TRUE ), select = select_spec( label = "Select variable:", - choices = variable_choices(ADRS, c("SEX", "RACE", "COUNTRY", "ARM", "PARAMCD", "AVISIT")), + choices = variable_choices(data[["ADRS"]], c("SEX", "RACE", "COUNTRY", "ARM", "PARAMCD", "AVISIT")), selected = "SEX", multiple = FALSE, fixed = FALSE @@ -230,7 +218,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL, c("SEX", "RACE")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE")), selected = NULL, multiple = FALSE, fixed = FALSE @@ -240,7 +228,7 @@ app <- teal::init( color = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -250,7 +238,7 @@ app <- teal::init( fill = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -260,7 +248,7 @@ app <- teal::init( size = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -277,21 +265,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADRS, "PARAMCD", "PARAM"), - selected = levels(ADRS$PARAMCD)[1], + choices = value_choices(data[["ADRS"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADRS"]]$PARAMCD)[1], multiple = FALSE, label = "Select response:" ), filter_spec( vars = "AVISIT", - choices = levels(ADRS$AVISIT), - selected = levels(ADRS$AVISIT)[1], + choices = levels(data[["ADRS"]]$AVISIT), + selected = levels(data[["ADRS"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADRS, c("AVALC", "AVAL")), + choices = variable_choices(data[["ADRS"]], c("AVALC", "AVAL")), selected = "AVALC", multiple = FALSE, label = "Select variable:" @@ -300,7 +288,7 @@ app <- teal::init( y = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("BMRKR1", "SEX", "AGE", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "SEX", "AGE", "RACE", "COUNTRY")), selected = "BMRKR1", multiple = FALSE, label = "Select variable:", @@ -310,7 +298,7 @@ app <- teal::init( row_facet = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("SEX", "RACE", "ARMCD", "PARAMCD")), + choices = variable_choices(data[["ADRS"]], c("SEX", "RACE", "ARMCD", "PARAMCD")), selected = "SEX", multiple = FALSE, label = "Select variable:" @@ -319,7 +307,7 @@ app <- teal::init( col_facet = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("SEX", "RACE", "ARMCD", "PARAMCD", "AVISIT")), + choices = variable_choices(data[["ADRS"]], c("SEX", "RACE", "ARMCD", "PARAMCD", "AVISIT")), selected = "ARMCD", multiple = FALSE, fixed = FALSE, @@ -334,21 +322,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADRS, "PARAMCD", "PARAM"), - selected = levels(ADRS$PARAMCD)[1], + choices = value_choices(data[["ADRS"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADRS"]]$PARAMCD)[1], multiple = FALSE, label = "Select response:" ), filter_spec( vars = "AVISIT", - choices = levels(ADRS$AVISIT), - selected = levels(ADRS$AVISIT)[1], + choices = levels(data[["ADRS"]]$AVISIT), + selected = levels(data[["ADRS"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADRS, c("AVALC", "AVAL")), + choices = variable_choices(data[["ADRS"]], c("AVALC", "AVAL")), selected = "AVALC", multiple = FALSE, label = "Select variable:" @@ -357,7 +345,7 @@ app <- teal::init( y = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("BMRKR1", "SEX", "AGE", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "SEX", "AGE", "RACE", "COUNTRY")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -368,15 +356,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select measurement:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) @@ -392,7 +380,7 @@ app <- teal::init( col_facet = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "AGE", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "AGE", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -403,7 +391,7 @@ app <- teal::init( color = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -413,7 +401,7 @@ app <- teal::init( fill = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -423,7 +411,7 @@ app <- teal::init( size = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -438,7 +426,7 @@ app <- teal::init( x = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVALC", "AVAL")), + choices = variable_choices(data[["ADRS"]], c("AVALC", "AVAL")), selected = "AVALC", multiple = FALSE, fixed = FALSE, @@ -448,7 +436,7 @@ app <- teal::init( y = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("SEX", "RACE", "COUNTRY", "ARMCD", "BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADRS"]], c("SEX", "RACE", "COUNTRY", "ARMCD", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE, @@ -458,7 +446,7 @@ app <- teal::init( row_facet = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVISIT", "PARAMCD")), + choices = variable_choices(data[["ADRS"]], c("AVISIT", "PARAMCD")), selected = "PARAMCD", multiple = FALSE, label = "Select variables:" @@ -467,7 +455,7 @@ app <- teal::init( col_facet = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVISIT", "PARAMCD")), + choices = variable_choices(data[["ADRS"]], c("AVISIT", "PARAMCD")), selected = "AVISIT", multiple = FALSE, label = "Select variables:" @@ -481,15 +469,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) @@ -506,15 +494,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) @@ -532,21 +520,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select category:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("RACE", "SEX", "ARMCD", "ACTARMCD")), + choices = variable_choices(data[["ADLB"]], c("RACE", "SEX", "ARMCD", "ACTARMCD")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -558,21 +546,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select category:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("RACE", "SEX", "ARMCD", "ACTARMCD")), + choices = variable_choices(data[["ADLB"]], c("RACE", "SEX", "ARMCD", "ACTARMCD")), selected = "ARMCD", multiple = FALSE, fixed = FALSE, @@ -583,7 +571,7 @@ app <- teal::init( color = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -593,7 +581,7 @@ app <- teal::init( fill = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -603,7 +591,7 @@ app <- teal::init( size = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = NULL, multiple = FALSE, fixed = FALSE, diff --git a/vignettes/using-cross-table.Rmd b/vignettes/using-cross-table.Rmd index 1af963d0f..2ab93bd9a 100644 --- a/vignettes/using-cross-table.Rmd +++ b/vignettes/using-cross-table.Rmd @@ -29,27 +29,26 @@ library(dplyr) # used to modify data sets ## Create data sets -Inside this app 5 datasets will be used +Inside this app 2 datasets will be used 1. `ADSL` A wide data set with subject data -2. `ADSL2` A wide data set with subject data -3. `ADRS` A long data set with response data for subjects at different time points of the study -4. `ADTTE` A long data set with time to event data -5. `ADLB` A long data set with lab measurements for each subject +2. `ADLB` A long data set with lab measurements for each subject ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide", echo=2:6} # nolint start -ADSL <- teal.modules.general::rADSL -ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) -ADRS <- teal.modules.general::rADRS -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ "N", - CHG > 1 ~ "P", - TRUE ~ "-" - ))) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] # nolint end ``` @@ -62,27 +61,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset( - "ADSL2", - ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset("ADLB", ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( modules( label = "Cross table", @@ -92,8 +71,8 @@ app <- teal::init( "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL), - selected = names(ADSL)[5], + choices = variable_choices(data[["ADSL"]]), + selected = names(data[["ADSL"]])[5], multiple = TRUE, fixed = FALSE, ordered = TRUE @@ -103,8 +82,8 @@ app <- teal::init( "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL), - selected = names(ADSL)[6], + choices = variable_choices(data[["ADSL"]]), + selected = names(data[["ADSL"]])[6], multiple = FALSE, fixed = FALSE ) @@ -116,12 +95,12 @@ app <- teal::init( dataname = "ADLB", filter = teal.transform::filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE ), select = select_spec( - choices = variable_choices(ADLB), + choices = variable_choices(data[["ADLB"]]), selected = "AVISIT", multiple = TRUE, fixed = FALSE, @@ -133,12 +112,12 @@ app <- teal::init( dataname = "ADLB", filter = teal.transform::filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE ), select = select_spec( - choices = variable_choices(ADLB), + choices = variable_choices(data[["ADLB"]]), selected = "LOQFL", multiple = FALSE, fixed = FALSE, diff --git a/vignettes/using-data-table.Rmd b/vignettes/using-data-table.Rmd index 8f012bb0e..77b8d4eb7 100644 --- a/vignettes/using-data-table.Rmd +++ b/vignettes/using-data-table.Rmd @@ -36,9 +36,15 @@ Inside this app 3 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB +}) +datanames <- c("ADSL", "ADTTE", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] # nolint end ``` @@ -50,12 +56,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset("ADLB", ADLB, code = "ADLB <- teal.modules.general::rADLB"), - check = TRUE - ), + data = data, modules = teal::modules( # two-datasets example tm_data_table( diff --git a/vignettes/using-outliers-module.Rmd b/vignettes/using-outliers-module.Rmd index c7d4e6812..be6c2325f 100644 --- a/vignettes/using-outliers-module.Rmd +++ b/vignettes/using-outliers-module.Rmd @@ -37,9 +37,15 @@ Inside this app 5 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADRS <- teal.modules.general::rADRS -ADLB <- teal.modules.general::rADLB +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADRS <- teal.modules.general::rADRS + ADLB <- teal.modules.general::rADLB +}) +datanames <- c("ADSL", "ADRS", "ADLB") +datanames(data) <- datanames +join_keys(data) <- default_cdisc_join_keys[datanames] # nolint end ``` @@ -52,12 +58,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADLB", ADLB, code = "ADLB <- teal.modules.general::rADLB"), - check = TRUE - ), + data = data, modules = teal::modules( # tm_outliers ---- modules( @@ -68,7 +69,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "AGE", fixed = FALSE ) @@ -77,7 +78,10 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL, subset = names(Filter(isTRUE, sapply(ADSL, is.factor)))), + choices = variable_choices( + data[["ADSL"]], + subset = names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) + ), selected = "RACE", multiple = FALSE, fixed = FALSE @@ -91,7 +95,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "AGE", fixed = FALSE ) @@ -100,7 +104,7 @@ app <- teal::init( dataname = "ADLB", select = select_spec( label = "Select variable:", - choices = variable_choices(ADLB, c("AVAL", "CHG2")), + choices = variable_choices(data[["ADLB"]], c("AVAL", "CHG2")), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -112,7 +116,10 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL, subset = names(Filter(isTRUE, sapply(ADSL, is.factor)))), + choices = variable_choices( + data[["ADSL"]], + subset = names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) + ), selected = "RACE", multiple = FALSE, fixed = FALSE @@ -126,7 +133,7 @@ app <- teal::init( dataname = "ADRS", select = select_spec( label = "Select variable:", - choices = variable_choices(ADRS, c("ADY", "EOSDY")), + choices = variable_choices(data[["ADRS"]], c("ADY", "EOSDY")), selected = "ADY", fixed = FALSE ) @@ -135,7 +142,7 @@ app <- teal::init( dataname = "ADLB", select = select_spec( label = "Select variable:", - choices = variable_choices(ADLB, c("AVAL", "CHG2")), + choices = variable_choices(data[["ADLB"]], c("AVAL", "CHG2")), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -147,7 +154,7 @@ app <- teal::init( dataname = "ADRS", select = select_spec( label = "Select variables:", - choices = variable_choices(ADRS, c("ARM", "ACTARM")), + choices = variable_choices(data[["ADRS"]], c("ARM", "ACTARM")), selected = "ARM", multiple = FALSE, fixed = FALSE @@ -157,7 +164,10 @@ app <- teal::init( dataname = "ADLB", select = select_spec( label = "Select variables:", - choices = variable_choices(ADLB, subset = names(Filter(isTRUE, sapply(ADLB, is.factor)))), + choices = variable_choices( + data[["ADLB"]], + subset = names(Filter(isTRUE, sapply(data[["ADLB"]], is.factor))) + ), selected = "RACE", multiple = FALSE, fixed = FALSE diff --git a/vignettes/using-regression-plots.Rmd b/vignettes/using-regression-plots.Rmd index ec4b54e9e..c409775a3 100644 --- a/vignettes/using-regression-plots.Rmd +++ b/vignettes/using-regression-plots.Rmd @@ -40,17 +40,27 @@ Inside this app 5 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) -ADRS <- teal.modules.general::rADRS -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ "N", - CHG > 1 ~ "P", - TRUE ~ "-" - ))) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADSL2 <- teal.modules.general::rADSL %>% + mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) + ADRS <- teal.modules.general::rADRS + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB") +datanames(data) <- datanames +jk <- default_cdisc_join_keys[datanames] +jk_adsl2 <- jk +names(jk_adsl2)[names(jk_adsl2) == "ADSL"] <- "ADSL2" +jk <- c(jk, jk_adsl2) +jk["ADSL2", "ADSL"] <- c("USUBJID", "STUDYID") # nolint end ``` @@ -63,27 +73,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset("ADSL2", ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( modules( label = "Regression plots", @@ -93,7 +83,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -103,7 +93,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL, c("AGE", "SEX", "RACE")), + choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")), selected = "AGE", multiple = TRUE, fixed = FALSE @@ -117,7 +107,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -127,7 +117,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL2, c("AGE", "SEX", "RACE")), + choices = variable_choices(data[["ADSL2"]], c("AGE", "SEX", "RACE")), selected = c("AGE", "RACE"), multiple = TRUE, fixed = FALSE @@ -141,7 +131,7 @@ app <- teal::init( dataname = "ADTTE", select = select_spec( label = "Select variable:", - choices = variable_choices(ADTTE, c("AVAL", "CNSR")), + choices = variable_choices(data[["ADTTE"]], c("AVAL", "CNSR")), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -149,7 +139,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select parameter:", vars = "PARAMCD", - choices = value_choices(ADTTE, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"), selected = "PFS", multiple = FALSE ) @@ -158,14 +148,14 @@ app <- teal::init( dataname = "ADTTE", select = select_spec( label = "Select variable:", - choices = variable_choices(ADTTE, c("AGE", "CNSR", "SEX")), + choices = variable_choices(data[["ADTTE"]], c("AGE", "CNSR", "SEX")), selected = c("AGE", "CNSR", "SEX"), multiple = TRUE ), filter = teal.transform::filter_spec( label = "Select parameter:", vars = "PARAMCD", - choices = value_choices(ADTTE, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"), selected = "PFS", multiple = FALSE ) @@ -178,15 +168,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[2], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[2], multiple = TRUE, label = "Select measurement:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[2], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[2], multiple = TRUE, label = "Select visit:" ) @@ -203,7 +193,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL, c("BMRKR1", "BMRKR2", "AGE")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "BMRKR2", "AGE")), selected = "AGE", multiple = TRUE, fixed = FALSE @@ -218,15 +208,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = TRUE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = TRUE, label = "Select visit:" ) @@ -243,21 +233,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select labs:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("AVAL", "AGE", "BMRKR1", "BMRKR2", "SEX", "ARM")), + choices = variable_choices(data[["ADLB"]], c("AVAL", "AGE", "BMRKR1", "BMRKR2", "SEX", "ARM")), selected = c("AVAL", "BMRKR1"), multiple = TRUE ) diff --git a/vignettes/using-response-plot.Rmd b/vignettes/using-response-plot.Rmd index 3990a1cbc..b60f74387 100644 --- a/vignettes/using-response-plot.Rmd +++ b/vignettes/using-response-plot.Rmd @@ -39,17 +39,27 @@ Inside this app 5 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) -ADRS <- teal.modules.general::rADRS -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ "N", - CHG > 1 ~ "P", - TRUE ~ "-" - ))) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADSL2 <- teal.modules.general::rADSL %>% + mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) + ADRS <- teal.modules.general::rADRS + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB") +datanames(data) <- datanames +jk <- default_cdisc_join_keys[datanames] +jk_adsl2 <- jk +names(jk_adsl2)[names(jk_adsl2) == "ADSL"] <- "ADSL2" +jk <- c(jk, jk_adsl2) +jk["ADSL2", "ADSL"] <- c("USUBJID", "STUDYID") # nolint end ``` @@ -62,29 +72,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset( - "ADSL2", - ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset( - "ADLB", - ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( modules( label = "Response plot", @@ -94,7 +82,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("BMRKR2", "ITTFL", "BEP01FL")), + choices = variable_choices(data[["ADSL"]], c("BMRKR2", "ITTFL", "BEP01FL")), selected = "BMRKR2", multiple = FALSE, fixed = FALSE @@ -104,7 +92,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("SEX", "RACE", "COUNTRY", "ARMCD", "STRATA1")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE", "COUNTRY", "ARMCD", "STRATA1")), selected = "ARMCD", multiple = FALSE, fixed = FALSE @@ -117,7 +105,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("BMRKR2", "ITTFL", "BEP01FL")), + choices = variable_choices(data[["ADSL"]], c("BMRKR2", "ITTFL", "BEP01FL")), selected = "BMRKR2", multiple = FALSE ) @@ -140,21 +128,21 @@ app <- teal::init( filter_spec( label = "Select parameter:", vars = "PARAMCD", - choices = levels(ADLB$PARAMCD), - selected = levels(ADLB$PARAMCD)[1], + choices = levels(data[["ADLB"]]$PARAMCD), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE ), filter_spec( label = "Select visit:", vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE ) ), select = select_spec( label = "Select variable:", - choices = variable_choices(ADLB, c("BMRKR2", "ITTFL", "BEP01FL")), + choices = variable_choices(data[["ADLB"]], c("BMRKR2", "ITTFL", "BEP01FL")), selected = "BMRKR2", multiple = FALSE ) @@ -165,15 +153,15 @@ app <- teal::init( filter_spec( label = "Select parameter:", vars = "PARAMCD", - choices = levels(ADRS$PARAMCD), - selected = levels(ADRS$PARAMCD)[3], + choices = levels(data[["ADRS"]]$PARAMCD), + selected = levels(data[["ADRS"]]$PARAMCD)[3], multiple = FALSE ), filter_spec( label = "Select visit:", vars = "AVISIT", - choices = levels(ADRS$AVISIT), - selected = levels(ADRS$AVISIT)[3], + choices = levels(data[["ADRS"]]$AVISIT), + selected = levels(data[["ADRS"]]$AVISIT)[3], multiple = FALSE ) ), @@ -197,7 +185,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("SEX", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "COUNTRY")), selected = NULL, multiple = FALSE ) @@ -210,21 +198,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = levels(ADLB$PARAMCD), - selected = levels(ADLB$PARAMCD)[2], + choices = levels(data[["ADLB"]]$PARAMCD), + selected = levels(data[["ADLB"]]$PARAMCD)[2], multiple = TRUE, label = "Select measurement:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[2], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[2], multiple = TRUE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("BMRKR2", "ITTFL", "BEP01FL")), + choices = variable_choices(data[["ADLB"]], c("BMRKR2", "ITTFL", "BEP01FL")), selected = "BMRKR2", multiple = FALSE, fixed = FALSE, @@ -234,7 +222,7 @@ app <- teal::init( x = teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(ADSL, c("ARMCD", "BMRKR1", "BMRKR2", "BEP01FL")), + choices = variable_choices(data[["ADSL"]], c("ARMCD", "BMRKR1", "BMRKR2", "BEP01FL")), selected = "BMRKR2", multiple = FALSE, fixed = FALSE @@ -246,7 +234,7 @@ app <- teal::init( response = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("BMRKR2", "AVALC", "BEP01FL")), + choices = variable_choices(data[["ADRS"]], c("BMRKR2", "AVALC", "BEP01FL")), selected = "AVALC", multiple = FALSE, fixed = TRUE, @@ -256,7 +244,7 @@ app <- teal::init( x = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVALC", "AGE", "SEX", "ARMCD", "STRATA1")), + choices = variable_choices(data[["ADRS"]], c("AVALC", "AGE", "SEX", "ARMCD", "STRATA1")), selected = "ARMCD", multiple = FALSE, fixed = FALSE, @@ -290,8 +278,8 @@ app <- teal::init( dataname = "ADLB", filter = teal.transform::filter_spec( vars = "PARAMCD", - choices = levels(ADLB$PARAMCD), - selected = levels(ADLB$PARAMCD)[2], + choices = levels(data[["ADLB"]]$PARAMCD), + selected = levels(data[["ADLB"]]$PARAMCD)[2], multiple = FALSE, label = "Select lab:" ), @@ -306,13 +294,13 @@ app <- teal::init( dataname = "ADLB", filter = teal.transform::filter_spec( vars = "PARAMCD", - choices = levels(ADLB$PARAMCD), - selected = levels(ADLB$PARAMCD)[1], + choices = levels(data[["ADLB"]]$PARAMCD), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), select = select_spec( - choices = variable_choices(ADLB, c("AVISIT", "PARAMCD", "BEP01FL")), + choices = variable_choices(data[["ADLB"]], c("AVISIT", "PARAMCD", "BEP01FL")), selected = "AVISIT", multiple = FALSE, fixed = TRUE @@ -323,21 +311,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = levels(ADLB$PARAMCD), - selected = levels(ADLB$PARAMCD)[1], + choices = levels(data[["ADLB"]]$PARAMCD), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("SEX", "RACE", "ARMCD")), + choices = variable_choices(data[["ADLB"]], c("SEX", "RACE", "ARMCD")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -349,21 +337,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = levels(ADLB$PARAMCD), - selected = levels(ADLB$PARAMCD)[1], + choices = levels(data[["ADLB"]]$PARAMCD), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("SEX", "RACE", "ARMCD")), + choices = variable_choices(data[["ADLB"]], c("SEX", "RACE", "ARMCD")), selected = NULL, multiple = FALSE, fixed = FALSE, diff --git a/vignettes/using-scatterplot-matrix.Rmd b/vignettes/using-scatterplot-matrix.Rmd index 5833ffb95..41fa0aeeb 100644 --- a/vignettes/using-scatterplot-matrix.Rmd +++ b/vignettes/using-scatterplot-matrix.Rmd @@ -40,17 +40,27 @@ Inside this app 5 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) -ADRS <- teal.modules.general::rADRS -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ "N", - CHG > 1 ~ "P", - TRUE ~ "-" - ))) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADSL2 <- teal.modules.general::rADSL %>% + mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) + ADRS <- teal.modules.general::rADRS + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB") +datanames(data) <- datanames +jk <- default_cdisc_join_keys[datanames] +jk_adsl2 <- jk +names(jk_adsl2)[names(jk_adsl2) == "ADSL"] <- "ADSL2" +jk <- c(jk, jk_adsl2) +jk["ADSL2", "ADSL"] <- c("USUBJID", "STUDYID") # nolint end ``` @@ -63,27 +73,7 @@ combinations of data sets. ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset( - "ADSL2", - ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset("ADLB", ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( modules( label = "Scatterplot matrix", @@ -94,7 +84,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = c("AGE", "RACE", "SEX", "BMRKR1", "BMRKR2"), multiple = TRUE, fixed = FALSE, @@ -109,7 +99,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL), + choices = variable_choices(data[["ADSL"]]), selected = c("AGE", "ACTARM", "SEX", "BMRKR1"), multiple = TRUE, fixed = FALSE, @@ -120,7 +110,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL2), + choices = variable_choices(data[["ADSL2"]]), selected = c("COUNTRY", "ACTARM", "STRATA1"), multiple = TRUE, fixed = FALSE, @@ -134,7 +124,7 @@ app <- teal::init( variables = teal.transform::data_extract_spec( dataname = "ADTTE", select = select_spec( - choices = variable_choices(ADTTE, c("AVAL", "BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADTTE"]], c("AVAL", "BMRKR1", "BMRKR2")), selected = c("AVAL", "BMRKR1", "BMRKR2"), multiple = TRUE, fixed = FALSE, @@ -150,7 +140,7 @@ app <- teal::init( dataname = "ADRS", select = select_spec( label = "Select variables:", - choices = variable_choices(ADRS), + choices = variable_choices(data[["ADRS"]]), selected = c("AVAL", "AVALC"), multiple = TRUE, fixed = FALSE, @@ -159,7 +149,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoints:", vars = c("PARAMCD", "AVISIT"), - choices = value_choices(ADRS, c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), + choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), selected = "OVRINV - SCREENING", multiple = FALSE ) @@ -168,7 +158,7 @@ app <- teal::init( dataname = "ADTTE", select = select_spec( label = "Select variables:", - choices = variable_choices(ADTTE), + choices = variable_choices(data[["ADTTE"]]), selected = c("AVAL", "CNSR"), multiple = TRUE, fixed = FALSE, @@ -177,7 +167,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select parameters:", vars = "PARAMCD", - choices = value_choices(ADTTE, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"), selected = "OS", multiple = TRUE ) diff --git a/vignettes/using-scatterplot.Rmd b/vignettes/using-scatterplot.Rmd index a9c24939f..805a360e3 100644 --- a/vignettes/using-scatterplot.Rmd +++ b/vignettes/using-scatterplot.Rmd @@ -40,17 +40,27 @@ Inside this app 5 datasets will be used ```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"} # nolint start -ADSL <- teal.modules.general::rADSL -ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) -ADRS <- teal.modules.general::rADRS -ADTTE <- teal.modules.general::rADTTE -ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ "N", - CHG > 1 ~ "P", - TRUE ~ "-" - ))) +data <- teal_data() +data <- within(data, { + ADSL <- teal.modules.general::rADSL + ADSL2 <- teal.modules.general::rADSL %>% + mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1)) + ADRS <- teal.modules.general::rADRS + ADTTE <- teal.modules.general::rADTTE + ADLB <- teal.modules.general::rADLB %>% + mutate(CHGC = as.factor(case_when( + CHG < 1 ~ "N", + CHG > 1 ~ "P", + TRUE ~ "-" + ))) +}) +datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB") +datanames(data) <- datanames +jk <- default_cdisc_join_keys[datanames] +jk_adsl2 <- jk +names(jk_adsl2)[names(jk_adsl2) == "ADSL"] <- "ADSL2" +jk <- c(jk, jk_adsl2) +jk["ADSL2", "ADSL"] <- c("USUBJID", "STUDYID") # nolint end ``` @@ -69,27 +79,7 @@ ggextra_available <- requireNamespace("ggExtra", quietly = TRUE) ``` ```{r, eval = ggextra_available, echo=TRUE, message=FALSE, warning=FALSE, results="hide"} app <- teal::init( - data = teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"), - teal.data::cdisc_dataset( - "ADSL2", - ADSL2, - keys = get_cdisc_keys("ADSL"), - code = "ADSL2 <- teal.modules.general::rADSL %>% - mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))" - ), - teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"), - teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"), - teal.data::cdisc_dataset("ADLB", ADLB, - code = "ADLB <- teal.modules.general::rADLB %>% - mutate(CHGC = as.factor(case_when( - CHG < 1 ~ 'N', - CHG > 1 ~ 'P', - TRUE ~ '-' - )))" - ), - check = TRUE - ), + data = data, modules = teal::modules( modules( label = "Scatterplot", @@ -99,7 +89,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "AGE", multiple = FALSE, fixed = FALSE @@ -109,7 +99,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -119,7 +109,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variables:", - choices = variable_choices(ADSL, c("RACE", "SEX")), + choices = variable_choices(data[["ADSL"]], c("RACE", "SEX")), selected = NULL, multiple = TRUE, fixed = FALSE @@ -133,7 +123,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADSL"]], c("BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -143,7 +133,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL2, c("AGE", "SEX")), + choices = variable_choices(data[["ADSL2"]], c("AGE", "SEX")), selected = "AGE", multiple = FALSE, fixed = FALSE @@ -153,7 +143,7 @@ app <- teal::init( dataname = "ADSL2", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL2, c("COUNTRY", "AGE", "RACE")), + choices = variable_choices(data[["ADSL2"]], c("COUNTRY", "AGE", "RACE")), selected = "COUNTRY", multiple = FALSE, fixed = FALSE @@ -166,7 +156,7 @@ app <- teal::init( dataname = "ADRS", select = select_spec( label = "Select variable:", - choices = variable_choices(ADRS), + choices = variable_choices(data[["ADRS"]]), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -174,7 +164,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select endpoint:", vars = c("PARAMCD", "AVISIT"), - choices = value_choices(ADRS, c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), + choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), selected = "OVRINV - SCREENING", multiple = FALSE ) @@ -183,7 +173,7 @@ app <- teal::init( dataname = "ADTTE", select = select_spec( label = "Select variable:", - choices = variable_choices(ADTTE), + choices = variable_choices(data[["ADTTE"]]), selected = "AVAL", multiple = FALSE, fixed = FALSE @@ -191,7 +181,7 @@ app <- teal::init( filter = teal.transform::filter_spec( label = "Select parameters:", vars = c("PARAMCD"), - choices = value_choices(ADTTE, "PARAMCD", "PARAM"), + choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"), selected = "OS", multiple = TRUE ) @@ -200,7 +190,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("AGE", "SEX")), + choices = variable_choices(data[["ADSL"]], c("AGE", "SEX")), selected = "AGE", multiple = FALSE, fixed = FALSE @@ -213,7 +203,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("SEX", "AGE", "BMRKR1", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "AGE", "BMRKR1", "COUNTRY")), selected = "AGE", multiple = FALSE, fixed = FALSE @@ -224,15 +214,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select measurement:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) @@ -249,7 +239,7 @@ app <- teal::init( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(ADSL, c("SEX", "AGE", "RACE", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("SEX", "AGE", "RACE", "COUNTRY")), selected = NULL, multiple = FALSE, fixed = FALSE @@ -261,7 +251,7 @@ app <- teal::init( x = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVAL", "BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADRS"]], c("AVAL", "BMRKR1", "BMRKR2")), selected = "AVAL", multiple = FALSE, fixed = FALSE, @@ -271,7 +261,7 @@ app <- teal::init( y = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AVAL", "BMRKR1", "BMRKR2")), + choices = variable_choices(data[["ADRS"]], c("AVAL", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE, @@ -281,7 +271,7 @@ app <- teal::init( color_by = teal.transform::data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(ADRS, c("AGE", "SEX", "RACE")), + choices = variable_choices(data[["ADRS"]], c("AGE", "SEX", "RACE")), selected = NULL, multiple = FALSE, fixed = FALSE, @@ -296,15 +286,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) @@ -321,15 +311,15 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) @@ -346,21 +336,21 @@ app <- teal::init( filter = list( filter_spec( vars = "PARAMCD", - choices = value_choices(ADLB, "PARAMCD", "PARAM"), - selected = levels(ADLB$PARAMCD)[1], + choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"), + selected = levels(data[["ADLB"]]$PARAMCD)[1], multiple = FALSE, label = "Select lab:" ), filter_spec( vars = "AVISIT", - choices = levels(ADLB$AVISIT), - selected = levels(ADLB$AVISIT)[1], + choices = levels(data[["ADLB"]]$AVISIT), + selected = levels(data[["ADLB"]]$AVISIT)[1], multiple = FALSE, label = "Select visit:" ) ), select = select_spec( - choices = variable_choices(ADLB, c("RACE", "SEX")), + choices = variable_choices(data[["ADLB"]], c("RACE", "SEX")), selected = "SEX", multiple = FALSE, fixed = FALSE, From f1a301444e99c723eafd8f97c33d20c8de0e0732 Mon Sep 17 00:00:00 2001 From: vedhav Date: Mon, 20 Nov 2023 11:02:02 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 0.2.16.9011 --- .pre-commit-config.yaml | 2 +- DESCRIPTION | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be27c3fb7..73075bd77 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9021 + rev: v0.3.2.9027 hooks: - id: style-files name: Style code with `styler` diff --git a/DESCRIPTION b/DESCRIPTION index e743c6ead..a36674746 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: teal.modules.general Title: General Modules to Add to a `teal` Application -Version: 0.2.16.9010 -Date: 2023-10-16 +Version: 0.2.16.9011 +Date: 2023-11-20 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre")), person("Pawel", "Rucki", , "pawel.rucki@roche.com", role = "aut"),