diff --git a/DESCRIPTION b/DESCRIPTION index 9eacf7966..e42207bf4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,7 @@ Imports: shinycssloaders (>= 1.0.0), shinyjs, shinyWidgets (>= 0.6.2), - teal.data (>= 0.3.0.9018), + teal.data (>= 0.3.0.9029), teal.logger (>= 0.1.1), teal.widgets (>= 0.4.0), utils diff --git a/R/FilteredDatasetDataframe.R b/R/FilteredDatasetDataframe.R index 06ca75112..a58eccdd1 100644 --- a/R/FilteredDatasetDataframe.R +++ b/R/FilteredDatasetDataframe.R @@ -122,8 +122,8 @@ DataframeFilteredDataset <- R6::R6Class( # nolint if (!identical(parent_dataname, character(0))) { join_keys <- private$join_keys - parent_keys <- names(join_keys) - dataset_keys <- unname(join_keys) + parent_keys <- unname(join_keys) + dataset_keys <- names(join_keys) y_arg <- if (length(parent_keys) == 0L) { parent_dataname @@ -240,11 +240,10 @@ DataframeFilteredDataset <- R6::R6Class( # nolint # Gets filter overview subjects number and returns a list # of the number of subjects of filtered/non-filtered datasets subject_keys <- if (length(private$parent_name) > 0) { - private$join_keys + names(private$join_keys) } else { self$get_keys() } - dataset <- self$get_dataset() data_filtered <- self$get_dataset(TRUE) if (length(subject_keys) == 0) { diff --git a/tests/testthat/test-FilteredData.R b/tests/testthat/test-FilteredData.R index ebf5a0bf9..176082ac4 100644 --- a/tests/testthat/test-FilteredData.R +++ b/tests/testthat/test-FilteredData.R @@ -35,7 +35,6 @@ testthat::test_that("filtered_data$datanames returns character vector of dataset testthat::test_that("datanames are ordered topologically from parent to child", { jk <- teal.data::join_keys(teal.data::join_key("parent", "child", c("id" = "id"))) - teal.data::parents(jk) <- list(child = "parent") iris2 <- transform(iris, id = seq_len(nrow(iris))) filtered_data <- FilteredData$new( list( @@ -94,7 +93,6 @@ testthat::test_that("set_datasets creates FilteredDataset object linked with par ) ) jk <- teal.data::join_keys(teal.data::join_key("parent", "child", c("id" = "id"))) - teal.data::parents(jk) <- list(child = "parent") iris2 <- transform(iris, id = seq_len(nrow(iris))) filtered_data <- test_class$new(data_objects = list(), join_keys = jk) filtered_data$set_dataset(data = head(iris), dataname = "parent") @@ -269,10 +267,9 @@ testthat::test_that("get_data returns an object filtered by set filters", { testthat::test_that("get_data of the child is dependent on the ancestor filter", { jk <- teal.data::join_keys( - teal.data::join_key("child", "parent", c("id" = "id")), - teal.data::join_key("grandchild", "child", c("id" = "id")) + teal.data::join_key("parent", "child", c("id" = "id")), + teal.data::join_key("child", "grandchild", c("id" = "id")) ) - teal.data::parents(jk) <- list(child = "parent", grandchild = "child") iris2 <- transform(iris, id = seq_len(nrow(iris))) filtered_data <- FilteredData$new( list( @@ -292,6 +289,31 @@ testthat::test_that("get_data of the child is dependent on the ancestor filter", ) }) +testthat::test_that("get_data of the child is dependent on the ancestor filter (mismatched columns)", { + jk <- teal.data::join_keys( + teal.data::join_key("parent", "child", c("pk" = "id")), + teal.data::join_key("child", "grandchild", c("id" = "id")) + ) + iris2 <- transform(iris, id = seq_len(nrow(iris))) + iris_parent <- dplyr::rename(iris2, pk = "id") + filtered_data <- FilteredData$new( + list( + grandchild = list(dataset = head(iris2)), + child = list(dataset = head(iris2)), + parent = list(dataset = head(iris_parent)) + ), + join_keys = jk + ) + filtered_data$set_filter_state(teal_slices( + teal_slice(dataname = "parent", varname = "pk", selected = c(1, 1), keep_na = FALSE, keep_inf = FALSE) + )) + + testthat::expect_identical( + shiny::isolate(filtered_data$get_data("grandchild", filtered = TRUE)), + dplyr::filter(iris2, id == 1) + ) +}) + # get_filter_state ---- testthat::test_that("get_filter_state returns `teal_slices` with features identical to those in input", { datasets <- FilteredData$new( @@ -603,10 +625,9 @@ testthat::test_that("get_filter_overview returns overview data.frame with filter testthat::test_that("get_filter_overview return counts based on reactive filtering by ancestors", { jk <- teal.data::join_keys( - teal.data::join_key("child", "parent", c("id" = "id")), - teal.data::join_key("grandchild", "child", c("id" = "id")) + teal.data::join_key("parent", "child", c("id" = "id")), + teal.data::join_key("child", "grandchild", c("id" = "id")) ) - teal.data::parents(jk) <- list(child = "parent", grandchild = "child") iris2 <- transform(iris, id = seq_len(nrow(iris))) filtered_data <- FilteredData$new( list(