From fc4493934e72b8ab5eaaa0d4458e0e28cfcdd726 Mon Sep 17 00:00:00 2001 From: Nikolas Burkoff Date: Wed, 22 Jun 2022 11:00:15 +0100 Subject: [PATCH] updates for teal.slice (#73) --- R/data_extract_filter_module.R | 4 ++-- R/data_extract_module.R | 14 ++++++----- R/data_merge_module.R | 6 ++--- R/format_data_extract.R | 10 +++----- R/resolve_delayed.R | 9 ++++--- man/data_extract_multiple_srv.Rd | 7 +++--- man/data_extract_srv.Rd | 7 +++--- man/data_merge_module.Rd | 3 +-- man/data_merge_srv.Rd | 3 +-- man/format_data_extract.Rd | 10 +++----- man/get_initial_filter_values.Rd | 4 ++-- man/resolve_delayed.Rd | 9 ++++--- .../shinytest/format_data_extract/app.R | 7 +++--- tests/testthat/test-choices_selected.R | 4 +--- tests/testthat/test-data_extract_module.R | 6 ++--- tests/testthat/test-data_extract_spec.R | 9 +++---- tests/testthat/test-data_extract_srv.R | 13 ++++++---- tests/testthat/test-data_merge_srv.R | 5 +--- tests/testthat/test-delayed_data_extract.R | 24 +++++++------------ tests/testthat/test-dplyr_call_examples.R | 5 +--- tests/testthat/test-filter_spec.R | 16 ++++++++----- tests/testthat/test-format_data_extract.R | 8 ++----- tests/testthat/test-resolve_delayed.R | 8 ++----- tests/testthat/test-select_spec.R | 9 +++---- tests/testthat/test-value_choices.R | 3 +-- tests/testthat/test-variable_choices.R | 4 ++-- vignettes/data-extract-merge.Rmd | 18 +++++++------- vignettes/data-extract.Rmd | 4 +--- vignettes/data-merge.Rmd | 6 ++--- 29 files changed, 105 insertions(+), 130 deletions(-) diff --git a/R/data_extract_filter_module.R b/R/data_extract_filter_module.R index e95804de..e751ecf1 100644 --- a/R/data_extract_filter_module.R +++ b/R/data_extract_filter_module.R @@ -119,8 +119,8 @@ data_extract_filter_srv <- function(id, datasets, filter) { #' @keywords internal #' #' @examples -#' filtered_data <- teal.slice:::FilteredData$new()$set_dataset( -#' teal.data::dataset("iris", utils::head(iris)) +#' filtered_data <- teal.slice::init_filtered_data( +#' list(iris = list(dataset = utils::head(iris))) #' ) #' filter <- filter_spec(vars = colnames(iris)[1]) #' filter$dataname <- "iris" diff --git a/R/data_extract_module.R b/R/data_extract_module.R index 6a61a027..bf25b7b3 100644 --- a/R/data_extract_module.R +++ b/R/data_extract_module.R @@ -287,9 +287,10 @@ check_data_extract_spec_react <- function(datasets, data_extract) { #' AGE = rpois(10, 30), #' BMRKR1 = rlnorm(10) #' ) -#' data <- teal.data::teal_data(teal.data::dataset("ADSL", ADSL)) -#' datasets <- teal.slice:::filtered_data_new(data) -#' teal.slice:::filtered_data_set(data, datasets) +#' datasets <- teal.slice::init_filtered_data( +#' list(ADSL = list(dataset = ADSL, keys = c("STUDYID", "USUBJID"), parent = character(0))), +#' cdisc = TRUE +#' ) #' #' adsl_extract <- data_extract_spec( #' dataname = "ADSL", @@ -437,9 +438,10 @@ data_extract_srv <- function(id, datasets, data_extract_spec) { #' BMRKR1 = rlnorm(10) #' ) #' -#' data <- teal.data::teal_data(teal.data::dataset("ADSL", ADSL)) -#' datasets <- teal.slice:::filtered_data_new(data) -#' teal.slice:::filtered_data_set(data, datasets) +#' datasets <- teal.slice::init_filtered_data( +#' list(ADSL = list(dataset = ADSL, keys = c("STUDYID", "USUBJID"), parent = character(0))), +#' cdisc = TRUE +#' ) #' #' xvar_extract <- data_extract_spec( #' dataname = "ADSL", diff --git a/R/data_merge_module.R b/R/data_merge_module.R index b01143c6..40196a70 100644 --- a/R/data_merge_module.R +++ b/R/data_merge_module.R @@ -44,8 +44,7 @@ #' teal.data::cdisc_dataset("ADSL", ADSL), #' teal.data::cdisc_dataset("ADLB", ADLB) #' ) -#' datasets <- teal.slice:::filtered_data_new(data) -#' teal.slice:::filtered_data_set(data, datasets) +#' datasets <- teal.slice::init_filtered_data(data) #' #' adsl_extract <- data_extract_spec( #' dataname = "ADSL", @@ -172,8 +171,7 @@ data_merge_module <- function(datasets, #' teal.data::cdisc_dataset("ADSL", ADSL), #' teal.data::cdisc_dataset("ADLB", ADLB) #' ) -#' datasets <- teal.slice:::filtered_data_new(data) -#' teal.slice:::filtered_data_set(data, datasets) +#' datasets <- teal.slice::init_filtered_data(data) #' #' adsl_extract <- data_extract_spec( #' dataname = "ADSL", diff --git a/R/format_data_extract.R b/R/format_data_extract.R index e8add499..e516f798 100644 --- a/R/format_data_extract.R +++ b/R/format_data_extract.R @@ -14,13 +14,9 @@ #' ) #' #' sample_filtered_data <- { -#' # create TealData -#' data <- teal.data::teal_data(teal.data::dataset("iris", iris)) -#' -#' # covert TealData to FilteredData -#' datasets <- teal.slice:::filtered_data_new(data) -#' teal.slice:::filtered_data_set(data, datasets) -#' datasets +#' teal.slice::init_filtered_data( +#' list(iris = list(dataset = iris)) +#' ) #' } #' #' if (interactive()) { diff --git a/R/resolve_delayed.R b/R/resolve_delayed.R index a6cad198..74125553 100644 --- a/R/resolve_delayed.R +++ b/R/resolve_delayed.R @@ -12,11 +12,14 @@ #' @examples #' library(scda) #' -#' ds <- teal.slice:::FilteredData$new() #' ADSL <- synthetic_cdisc_data("latest")$adsl -#' attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") #' shiny::isolate({ -#' ds$set_dataset(teal.data::dataset("ADSL", ADSL)) +#' ds <- teal.slice::init_filtered_data( +#' list(ADSL = list( +#' dataset = ADSL, keys = teal.data::get_cdisc_keys("ADSL"), parent = character(0) +#' )), +#' cdisc = TRUE +#' ) #' #' # value_choices example #' v1 <- value_choices("ADSL", "SEX", "SEX") diff --git a/man/data_extract_multiple_srv.Rd b/man/data_extract_multiple_srv.Rd index 949a621f..1acfacb0 100644 --- a/man/data_extract_multiple_srv.Rd +++ b/man/data_extract_multiple_srv.Rd @@ -34,9 +34,10 @@ ADSL <- data.frame( BMRKR1 = rlnorm(10) ) -data <- teal.data::teal_data(teal.data::dataset("ADSL", ADSL)) -datasets <- teal.slice:::filtered_data_new(data) -teal.slice:::filtered_data_set(data, datasets) +datasets <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = ADSL, keys = c("STUDYID", "USUBJID"), parent = character(0))), + cdisc = TRUE +) xvar_extract <- data_extract_spec( dataname = "ADSL", diff --git a/man/data_extract_srv.Rd b/man/data_extract_srv.Rd index 0379c3ea..f6801680 100644 --- a/man/data_extract_srv.Rd +++ b/man/data_extract_srv.Rd @@ -43,9 +43,10 @@ ADSL <- data.frame( AGE = rpois(10, 30), BMRKR1 = rlnorm(10) ) -data <- teal.data::teal_data(teal.data::dataset("ADSL", ADSL)) -datasets <- teal.slice:::filtered_data_new(data) -teal.slice:::filtered_data_set(data, datasets) +datasets <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = ADSL, keys = c("STUDYID", "USUBJID"), parent = character(0))), + cdisc = TRUE +) adsl_extract <- data_extract_spec( dataname = "ADSL", diff --git a/man/data_merge_module.Rd b/man/data_merge_module.Rd index 8dbd227a..d4518963 100644 --- a/man/data_merge_module.Rd +++ b/man/data_merge_module.Rd @@ -62,8 +62,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADSL", ADSL), teal.data::cdisc_dataset("ADLB", ADLB) ) -datasets <- teal.slice:::filtered_data_new(data) -teal.slice:::filtered_data_set(data, datasets) +datasets <- teal.slice::init_filtered_data(data) adsl_extract <- data_extract_spec( dataname = "ADSL", diff --git a/man/data_merge_srv.Rd b/man/data_merge_srv.Rd index 675b1913..e7aa2f05 100644 --- a/man/data_merge_srv.Rd +++ b/man/data_merge_srv.Rd @@ -64,8 +64,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADSL", ADSL), teal.data::cdisc_dataset("ADLB", ADLB) ) -datasets <- teal.slice:::filtered_data_new(data) -teal.slice:::filtered_data_set(data, datasets) +datasets <- teal.slice::init_filtered_data(data) adsl_extract <- data_extract_spec( dataname = "ADSL", diff --git a/man/format_data_extract.Rd b/man/format_data_extract.Rd index 08d56f86..a73100c5 100644 --- a/man/format_data_extract.Rd +++ b/man/format_data_extract.Rd @@ -26,13 +26,9 @@ simple_des <- data_extract_spec( ) sample_filtered_data <- { - # create TealData - data <- teal.data::teal_data(teal.data::dataset("iris", iris)) - - # covert TealData to FilteredData - datasets <- teal.slice:::filtered_data_new(data) - teal.slice:::filtered_data_set(data, datasets) - datasets + teal.slice::init_filtered_data( + list(iris = list(dataset = iris)) + ) } if (interactive()) { diff --git a/man/get_initial_filter_values.Rd b/man/get_initial_filter_values.Rd index 411a216f..d3db1479 100644 --- a/man/get_initial_filter_values.Rd +++ b/man/get_initial_filter_values.Rd @@ -20,8 +20,8 @@ Returns the initial values for the \code{vals} widget of a \code{filter_spec} object. } \examples{ -filtered_data <- teal.slice:::FilteredData$new()$set_dataset( - teal.data::dataset("iris", utils::head(iris)) +filtered_data <- teal.slice::init_filtered_data( + list(iris = list(dataset = utils::head(iris))) ) filter <- filter_spec(vars = colnames(iris)[1]) filter$dataname <- "iris" diff --git a/man/resolve_delayed.Rd b/man/resolve_delayed.Rd index 2c894178..d268be96 100644 --- a/man/resolve_delayed.Rd +++ b/man/resolve_delayed.Rd @@ -20,11 +20,14 @@ Resolved object. \examples{ library(scda) -ds <- teal.slice:::FilteredData$new() ADSL <- synthetic_cdisc_data("latest")$adsl -attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") shiny::isolate({ - ds$set_dataset(teal.data::dataset("ADSL", ADSL)) + ds <- teal.slice::init_filtered_data( + list(ADSL = list( + dataset = ADSL, keys = teal.data::get_cdisc_keys("ADSL"), parent = character(0) + )), + cdisc = TRUE + ) # value_choices example v1 <- value_choices("ADSL", "SEX", "SEX") diff --git a/tests/testthat/shinytest/format_data_extract/app.R b/tests/testthat/shinytest/format_data_extract/app.R index 785fdfe3..c517f5da 100644 --- a/tests/testthat/shinytest/format_data_extract/app.R +++ b/tests/testthat/shinytest/format_data_extract/app.R @@ -5,10 +5,9 @@ simple_des <- teal.transform::data_extract_spec( ) sample_filtered_data <- { - data <- teal.data::teal_data(teal.data::dataset("iris", iris)) - datasets <- teal.slice:::filtered_data_new(data) - teal.slice:::filtered_data_set(data, datasets) - datasets + teal.slice::init_filtered_data( + list(iris = list(dataset = iris)) + ) } ui <- shiny::fluidPage( diff --git a/tests/testthat/test-choices_selected.R b/tests/testthat/test-choices_selected.R index 21bc954e..f384996b 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -1,9 +1,7 @@ adsl <- as.data.frame(as.list(setNames(nm = teal.data::get_cdisc_keys("ADSL")))) adtte <- as.data.frame(as.list(setNames(nm = teal.data::get_cdisc_keys("ADTTE")))) data <- teal.data::cdisc_data(teal.data::cdisc_dataset("ADSL", adsl), teal.data::cdisc_dataset("ADTTE", adtte)) - -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( diff --git a/tests/testthat/test-data_extract_module.R b/tests/testthat/test-data_extract_module.R index 030a3d66..bd83fd6b 100644 --- a/tests/testthat/test-data_extract_module.R +++ b/tests/testthat/test-data_extract_module.R @@ -144,7 +144,7 @@ testthat::test_that("Multiple datasets", { }) testthat::test_that("get_initial_filters_values returns empty strings if vars_selected is NULL", { - filtered_data <- teal.slice:::FilteredData$new() + filtered_data <- teal.slice::init_filtered_data(list(iris = list(dataset = utils::head(iris)))) filter <- filter_spec(vars = "test") filter$vars_selected <- NULL testthat::expect_equal( @@ -155,7 +155,7 @@ testthat::test_that("get_initial_filters_values returns empty strings if vars_se testthat::test_that("get_initial_filters_values returns all column values and the selected option if choices is NULL", { - filtered_data <- teal.slice:::FilteredData$new()$set_dataset(teal.data::dataset("iris", utils::head(iris))) + filtered_data <- teal.slice::init_filtered_data(list(iris = list(dataset = utils::head(iris)))) filter <- filter_spec(vars = colnames(iris)[1]) filter$choices <- NULL filter$dataname <- "iris" @@ -167,7 +167,7 @@ testthat::test_that("get_initial_filters_values returns all column values and th }) testthat::test_that("get_initial_filters_values returns the selected and choices if they are not null", { - filtered_data <- teal.slice:::FilteredData$new()$set_dataset(teal.data::dataset("iris", utils::head(iris))) + filtered_data <- teal.slice::init_filtered_data(list(iris = list(dataset = utils::head(iris)))) filter <- filter_spec(vars = colnames(iris)[length(colnames(iris))]) filter$choices <- "setosa" filter$selected <- "setosa" diff --git a/tests/testthat/test-data_extract_spec.R b/tests/testthat/test-data_extract_spec.R index e73f53fd..0602d0fd 100644 --- a/tests/testthat/test-data_extract_spec.R +++ b/tests/testthat/test-data_extract_spec.R @@ -188,9 +188,11 @@ test_that("delayed data_extract_spec works", { expect_equal(names(expected_spec), names(mix2)) expect_equal(names(expected_spec), names(mix3)) - ds <- teal.slice:::CDISCFilteredData$new() isolate({ - ds$set_dataset(teal.data::cdisc_dataset("ADSL", ADSL)) + ds <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = ADSL, keys = c("USUBJID", "STUDYID"), parent = character(0))), + cdisc = TRUE + ) expect_identical(expected_spec, resolve_delayed(delayed_spec, ds)) expect_identical(expected_spec, resolve_delayed(mix1, ds)) expect_identical(expected_spec, resolve_delayed(mix2, ds)) @@ -213,8 +215,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADTTE", adtte) ) -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( diff --git a/tests/testthat/test-data_extract_srv.R b/tests/testthat/test-data_extract_srv.R index f8aa940d..c7b65592 100644 --- a/tests/testthat/test-data_extract_srv.R +++ b/tests/testthat/test-data_extract_srv.R @@ -1,8 +1,10 @@ adsl_df <- as.data.frame(as.list(stats::setNames(nm = teal.data::get_cdisc_keys("ADSL")))) adsl <- teal.data::cdisc_dataset("ADSL", adsl_df) -datasets <- teal.slice:::CDISCFilteredData$new() -datasets$set_dataset(adsl) +datasets <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = adsl_df, keys = teal.data::get_cdisc_keys("ADSL"), parent = character(0))), + cdisc = TRUE +) adsl_extract <- data_extract_spec( dataname = "ADSL", @@ -103,8 +105,9 @@ testthat::test_that("data_extract_srv throws if data_extract_spec's dataname is ) }) -filtered_data <- teal.slice:::FilteredData$new() -filtered_data$set_dataset(teal.data::dataset("iris", iris)) +filtered_data <- teal.slice::init_filtered_data( + list(iris = list(dataset = iris)) +) testthat::test_that("data_extract_multiple_srv accepts a named list of `data_extract_spec`", { shiny::withReactiveDomain( @@ -188,7 +191,7 @@ testthat::test_that("data_extract_multiple_srv throws if data_extract is not a n shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), expr = testthat::expect_error( - data_extract_multiple_srv(list(1), datasets = teal.slice:::FilteredData$new()), + data_extract_multiple_srv(list(1), datasets = teal.slice::init_filtered_data(list(iris = list(dataset = iris)))), regexp = "Assertion on 'data_extract' failed: Must have names" ) ) diff --git a/tests/testthat/test-data_merge_srv.R b/tests/testthat/test-data_merge_srv.R index 18b8c53c..1cb9c256 100644 --- a/tests/testthat/test-data_merge_srv.R +++ b/tests/testthat/test-data_merge_srv.R @@ -7,10 +7,7 @@ adsl <- teal.data::cdisc_dataset("ADSL", adsl) adlb <- teal.data::cdisc_dataset("ADLB", adlb) data <- teal.data::cdisc_data(adsl, adlb) -datasets_used <- teal.slice:::CDISCFilteredData$new() - -datasets_used$set_dataset(adsl) -datasets_used$set_dataset(adlb) +datasets_used <- teal.slice::init_filtered_data(data) adsl_data_extract_srv_output <- list( diff --git a/tests/testthat/test-delayed_data_extract.R b/tests/testthat/test-delayed_data_extract.R index e11da289..3260ce1c 100644 --- a/tests/testthat/test-delayed_data_extract.R +++ b/tests/testthat/test-delayed_data_extract.R @@ -9,9 +9,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADTTE", ADTTE) ) - -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( @@ -67,8 +65,7 @@ test_that("Delayed data extract - single data connector with two scda dataset co connector$pull() } # test delayed data extract - ds <- teal.slice:::CDISCFilteredData$new() - isolate(teal.slice:::filtered_data_set(data, ds)) + ds <- teal.slice::init_filtered_data(data) ADSL <- data$get_dataset("ADSL")$get_raw_data() # nolint ADAE <- data$get_dataset("ADAE")$get_raw_data() # nolint @@ -102,8 +99,7 @@ test_that("Delayed choices selected - single data connector with two scda datase for (connector in data$get_connectors()) { connector$pull() } - ds <- teal.slice:::CDISCFilteredData$new() - isolate(teal.slice:::filtered_data_set(data, ds)) + ds <- teal.slice::init_filtered_data(data) ADSL <- data$get_dataset("ADSL")$get_raw_data() # nolint choices_expected <- variable_choices(ADSL, key = teal.data::get_cdisc_keys("ADSL")) @@ -151,8 +147,7 @@ test_that("Delayed data extract - filtered", { for (connector in data$get_connectors()) { connector$pull() } - ds <- teal.slice:::CDISCFilteredData$new() - isolate(teal.slice:::filtered_data_set(data, ds)) + ds <- teal.slice::init_filtered_data(data) ADSL <- data$get_dataset("ADSL")$get_raw_data() # nolint ADRS <- data$get_dataset("ADRS")$get_raw_data() # nolint @@ -238,8 +233,7 @@ test_that("Delayed extract filter concatenated - single data connector with two for (connector in data$get_connectors()) { connector$pull() } - ds <- teal.slice:::CDISCFilteredData$new() - isolate(teal.slice:::filtered_data_set(data, ds)) + ds <- teal.slice::init_filtered_data(data) ADSL <- data$get_dataset("ADSL")$get_raw_data() # nolint ADRS <- data$get_dataset("ADRS")$get_raw_data() # nolint @@ -351,8 +345,7 @@ test_that("Delayed extract two filters - single data connector with two scda dat for (connector in data$get_connectors()) { connector$pull() } - ds <- teal.slice:::CDISCFilteredData$new() - isolate(teal.slice:::filtered_data_set(data, ds)) + ds <- teal.slice::init_filtered_data(data) ADSL <- data$get_dataset("ADSL")$get_raw_data() # nolint ADRS <- data$get_dataset("ADRS")$get_raw_data() # nolint @@ -416,7 +409,7 @@ test_that("Delayed extract two filters - single data connector with two scda dat test_that("Delayed extract - TealData with single dataset and multiple connectors", { adsl <- teal.data::dataset( dataname = "ADSL", - synthetic_cdisc_data("latest")$adsl, + scda::synthetic_cdisc_data("latest")$adsl, keys = teal.data::get_cdisc_keys("ADSL"), code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl", label = "ADSL" @@ -475,8 +468,7 @@ test_that("Delayed extract - TealData with single dataset and multiple connector for (connector in data$get_connectors()) { connector$pull() } - ds <- teal.slice:::CDISCFilteredData$new() - isolate(teal.slice:::filtered_data_set(data, ds)) + ds <- teal.slice::init_filtered_data(data) ADSL <- data$get_dataset("ADSL")$get_raw_data() # nolint ADRS <- data$get_dataset("ADRS")$get_raw_data() # nolint diff --git a/tests/testthat/test-dplyr_call_examples.R b/tests/testthat/test-dplyr_call_examples.R index afba9f6d..941507d7 100644 --- a/tests/testthat/test-dplyr_call_examples.R +++ b/tests/testthat/test-dplyr_call_examples.R @@ -3465,10 +3465,7 @@ testthat::test_that("Universal example", { testthat::expect_silent(data$set_check(check = TRUE)) testthat::expect_true(data$check()) - datasets <- teal.slice:::filtered_data_new.TealData(x = data) - isolate( - teal.slice:::filtered_data_set.TealData(data = data, datasets = datasets) - ) + datasets <- teal.slice::init_filtered_data(data) merged_datasets <- isolate( merge_datasets( diff --git a/tests/testthat/test-filter_spec.R b/tests/testthat/test-filter_spec.R index c61fbaa4..d98769f5 100644 --- a/tests/testthat/test-filter_spec.R +++ b/tests/testthat/test-filter_spec.R @@ -158,8 +158,10 @@ test_that("delayed filter_spec", { expect_equal(names(expected_spec), names(delayed)) - ds <- teal.slice:::CDISCFilteredData$new() - isolate(ds$set_dataset(teal.data::cdisc_dataset("ADSL", ADSL))) + ds <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = ADSL, keys = c("USUBJID", "STUDYID"), parent = character(0))), + cdisc = TRUE + ) result_spec <- isolate(resolve_delayed(delayed, ds)) expect_identical(expected_spec, isolate(resolve_delayed(delayed, ds))) }) @@ -243,8 +245,11 @@ test_that("delayed filter_spec works", { expect_equal(names(expected_spec), names(delayed)) - ds <- teal.slice:::FilteredData$new() - isolate(ds$set_dataset(teal.data::dataset("ADSL", ADSL))) + ds <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = ADSL)), + cdisc = TRUE + ) + delayed$dataname <- "ADSL" expected_spec$dataname <- "ADSL" expect_identical( @@ -280,8 +285,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADTTE", adtte) ) -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( diff --git a/tests/testthat/test-format_data_extract.R b/tests/testthat/test-format_data_extract.R index e063b970..1df8666f 100644 --- a/tests/testthat/test-format_data_extract.R +++ b/tests/testthat/test-format_data_extract.R @@ -34,12 +34,8 @@ testthat::test_that("format_data_extract returns a string representation of the }) testthat::test_that("format_data_extract integrates with data_extract_srv", { - sample_filtered_data <- { - data <- teal.data::teal_data(teal.data::dataset("iris", iris)) - datasets <- teal.slice:::filtered_data_new(data) - teal.slice:::filtered_data_set(data, datasets) - datasets - } + sample_filtered_data <- teal.slice::init_filtered_data(list(iris = list(dataset = iris))) + simple_des <- data_extract_spec( dataname = "iris", diff --git a/tests/testthat/test-resolve_delayed.R b/tests/testthat/test-resolve_delayed.R index 9555e710..425c5624 100644 --- a/tests/testthat/test-resolve_delayed.R +++ b/tests/testthat/test-resolve_delayed.R @@ -7,8 +7,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADTTE", adtte) ) -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) testthat::test_that("resolve_delayed_expr works correctly", { # function assumptions check @@ -87,17 +86,14 @@ testthat::test_that("resolve_delayed.list works correctly", { testthat::test_that("resolving delayed choices removes selected not in choices and give a log output", { - iris_dataset <- teal.data::dataset("IRIS", head(iris)) - c_s <- choices_selected( choices = variable_choices("IRIS", c("Sepal.Length", "Sepal.Width")), selected = variable_choices("IRIS", c("Petal.Length", "Sepal.Width")) ) - ds <- teal.slice:::FilteredData$new() output <- testthat::capture_output({ shiny::isolate({ - teal.slice:::filtered_data_set(teal.data::teal_data(iris_dataset), ds) + ds <- teal.slice::init_filtered_data(list(IRIS = list(dataset = head(iris)))) resolved_cs <- resolve_delayed(c_s, ds) }) }) diff --git a/tests/testthat/test-select_spec.R b/tests/testthat/test-select_spec.R index 38265621..67853271 100644 --- a/tests/testthat/test-select_spec.R +++ b/tests/testthat/test-select_spec.R @@ -97,8 +97,10 @@ test_that("resolve_delayed select_spec works", { expect_equal(names(expected_spec), names(delayed_spec)) - ds <- teal.slice:::CDISCFilteredData$new() - isolate(ds$set_dataset(teal.data::dataset("ADSL", ADSL))) + ds <- teal.slice::init_filtered_data( + list(ADSL = list(dataset = ADSL, parent = character(0), keys = c("USUBJID", "SUBJID"))), + cdisc = TRUE + ) expect_identical(expected_spec, isolate(resolve_delayed(delayed_spec, ds))) }) @@ -110,8 +112,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADTTE", adtte) ) -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( diff --git a/tests/testthat/test-value_choices.R b/tests/testthat/test-value_choices.R index 9931400e..accc10ff 100644 --- a/tests/testthat/test-value_choices.R +++ b/tests/testthat/test-value_choices.R @@ -7,8 +7,7 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADTTE", adtte) ) -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) +ds <- teal.slice::init_filtered_data(data) testthat::test_that("Will output warnings when value_choices applied on datasets with missing values and / or labels", { data <- data.frame( diff --git a/tests/testthat/test-variable_choices.R b/tests/testthat/test-variable_choices.R index fa0c4cab..e7b7a795 100644 --- a/tests/testthat/test-variable_choices.R +++ b/tests/testthat/test-variable_choices.R @@ -6,8 +6,8 @@ data <- teal.data::cdisc_data( teal.data::cdisc_dataset("ADSL", adsl), teal.data::cdisc_dataset("ADTTE", adtte) ) -ds <- teal.slice:::CDISCFilteredData$new() -isolate(teal.slice:::filtered_data_set(data, ds)) + +ds <- teal.slice::init_filtered_data(data) test_that("Can create variable_choices with datasets with no or missing labels", { example_data <- data.frame(USUBJID = 1:2, STUDYID = 1:1) diff --git a/vignettes/data-extract-merge.Rmd b/vignettes/data-extract-merge.Rmd index 1e51e822..25c97ac5 100644 --- a/vignettes/data-extract-merge.Rmd +++ b/vignettes/data-extract-merge.Rmd @@ -20,16 +20,16 @@ knitr::opts_chunk$set( #### Combining data-extract with data-merge -`teal.transform` provides `data_merge_srv` which converts `data_extract_srv` into R expression to transform data -for analytical purposes. For example, we may wish to select `AGE` from `ADSL` and select `AVAL` from `ADTTE` filtered -for rows where `PARAMCD` is `OS` and merge the results (using the primary keys) to create an analysis dataset +`teal.transform` provides `data_merge_srv` which converts `data_extract_srv` into R expression to transform data +for analytical purposes. For example, we may wish to select `AGE` from `ADSL` and select `AVAL` from `ADTTE` filtered +for rows where `PARAMCD` is `OS` and merge the results (using the primary keys) to create an analysis dataset `ANL` to be used in the module, as this diagram shows: ```{r echo=FALSE, out.width='100%'} knitr::include_graphics("./images/data_extract_spec/basic_concept.png") ``` -In the following code block we create a `data_extract_spec` object per dataset as illustrated above. +In the following code block we create a `data_extract_spec` object per dataset as illustrated above. ```{r} library(teal.transform) @@ -67,7 +67,7 @@ data_extracts <- list(adsl_extract = adsl_extract, adtte_extract = adtte_extract #### Example module Here, we create the `merge_ui` and the `merge_srv` functions which will be used to create the `ui` and the `srv` -components of the shiny app, respectively. +components of the shiny app, respectively. ```{r} merge_ui <- function(id, data_extracts) { @@ -108,11 +108,11 @@ merge_srv <- function(id, datasets, data_extracts) { Output from `data_extract_srv` (`reactive`) should be passed to `data_merge_srv` together with `datasets` (`FilteredData`). `data_merge_srv` returns a reactive list containing merged data and information needed to perform -the transformation - see more in `data_merge_srv` documentation. +the transformation - see more in `data_merge_srv` documentation. #### Example data -`teal.transform` functions depend on a `FilteredData` object from the `teal.slice` package. For example purposes we define a +`teal.transform` functions depend on a `FilteredData` object from the `teal.slice` package. For example purposes we define a wrapper function to initialize the necessary object: ```{r} @@ -123,9 +123,7 @@ sample_filtered_data <- function() { data <- teal.data::cdisc_data(adsl, adtte) # covert TealData to FilteredData - datasets <- teal.slice:::filtered_data_new(data) - teal.slice:::filtered_data_set(data, datasets) - datasets + teal.slice::init_filtered_data(data) } datasets <- sample_filtered_data() diff --git a/vignettes/data-extract.Rmd b/vignettes/data-extract.Rmd index 08ec426a..111206cf 100644 --- a/vignettes/data-extract.Rmd +++ b/vignettes/data-extract.Rmd @@ -78,9 +78,7 @@ sample_filtered_data <- function() { data <- teal.data::cdisc_data(adsl, adtte) # covert TealData to FilteredData - datasets <- teal.slice:::filtered_data_new(data) - teal.slice:::filtered_data_set(data, datasets) - datasets + teal.slice::init_filtered_data(data) } datasets <- sample_filtered_data() diff --git a/vignettes/data-merge.Rmd b/vignettes/data-merge.Rmd index a08f7e73..1d92a6b3 100644 --- a/vignettes/data-merge.Rmd +++ b/vignettes/data-merge.Rmd @@ -99,10 +99,8 @@ sample_filtered_data <- function() { adtte <- teal.data::cdisc_dataset("ADTTE", scda::synthetic_cdisc_data("latest")$adtte) data <- teal.data::cdisc_data(adsl, adtte) - # convert TealData to FilteredData - datasets <- teal.slice:::filtered_data_new(data) - teal.slice:::filtered_data_set(data, datasets) - datasets + # covert TealData to FilteredData + teal.slice::init_filtered_data(data) } datasets <- sample_filtered_data()