Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

updates for teal.slice #73

Merged
merged 6 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/data_extract_filter_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions R/data_extract_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions R/data_merge_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions R/format_data_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 6 additions & 3 deletions R/resolve_delayed.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions man/data_extract_multiple_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/data_extract_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/data_merge_module.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/data_merge_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions man/format_data_extract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/get_initial_filter_values.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/resolve_delayed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions tests/testthat/shinytest/format_data_extract/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-choices_selected.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-data_extract_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-data_extract_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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(
Expand Down
13 changes: 8 additions & 5 deletions tests/testthat/test-data_extract_srv.R
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
)
)
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test-data_merge_srv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 8 additions & 16 deletions tests/testthat/test-delayed_data_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading