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

471 remove CodeClass from FilteredData #488

Merged
merged 11 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal.slice 0.4.0.9022
# teal.slice 0.4.0.9023

### Miscellaneous

Expand Down Expand Up @@ -27,6 +27,7 @@
* Setting filters using a list is now deprecated. Use `teal_slices` and `teal_slice` instead.
* Removed `CDISCFilteredData` and `CDISCFilteredDataset` and implementing `JoinKeys` handling in their parent classes (`FilteredData` and `DefaultFilteredDataset`).
* Specifying set of filterable columns is done through `include_varnames` and `exclude_varnames` in `teal_slices`. Specifying `attr(, "filterable")` is hard deprecated.
* Removed private fields `$code` and `$check` from `FilteredData` class and made appropriate changes to constructor and `init_filtered_data`.

chlebowa marked this conversation as resolved.
Show resolved Hide resolved
# teal.slice 0.3.0

Expand Down
6 changes: 2 additions & 4 deletions R/FilteredData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ init_filtered_data.TealData <- function(x, # nolint

#' @keywords internal
#' @export
init_filtered_data.default <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint
init_filtered_data.default <- function(x, join_keys = teal.data::join_keys(), code, check) { # nolint
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
checkmate::assert_list(x, any.missing = FALSE, names = "unique")
checkmate::assert_class(code, "CodeClass", null.ok = TRUE)
checkmate::assert_class(join_keys, "join_keys")
checkmate::assert_flag(check)
FilteredData$new(x, join_keys = join_keys, code = code, check = check)
FilteredData$new(x, join_keys = join_keys)
}

#' Validate dataset arguments
Expand Down
69 changes: 1 addition & 68 deletions R/FilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,11 @@ FilteredData <- R6::R6Class( # nolint
#' should named elements containing `data.frame` or `MultiAssayExperiment`.
#' Names of the list will serve as `dataname`.
#' @param join_keys (`join_keys` or NULL) see [`teal.data::join_keys()`].
#' @param code (`CodeClass` or `NULL`) see [`teal.data::CodeClass`].
#' @param check (`logical(1)`) whether data has been check against reproducibility.
#'
initialize = function(data_objects, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) {
initialize = function(data_objects, join_keys = teal.data::join_keys()) {
checkmate::assert_list(data_objects, any.missing = FALSE, min.len = 0, names = "unique")
# Note the internals of data_objects are checked in set_dataset
checkmate::assert_class(join_keys, "join_keys")
checkmate::assert_class(code, "CodeClass", null.ok = TRUE)
checkmate::assert_flag(check)

self$set_check(check)
if (!is.null(code)) {
self$set_code(code)
}

self$set_join_keys(join_keys)
child_parent <- sapply(
Expand Down Expand Up @@ -210,21 +201,6 @@ FilteredData <- R6::R6Class( # nolint
private$get_filtered_dataset(dataname)$get_call()
},

#' @description
#' Gets the R preprocessing code string that generates the unfiltered datasets.
#'
#' @param dataname (`character(1)`) name(s) of dataset(s)
#'
#' @return (`character(1)`) deparsed code
#'
get_code = function(dataname = self$datanames()) {
if (!is.null(private$code)) {
paste0(private$code$get_code(dataname), collapse = "\n")
} else {
paste0("# No pre-processing code provided")
}
},

#' @description
#' Gets filtered or unfiltered dataset.
#'
Expand All @@ -241,15 +217,6 @@ FilteredData <- R6::R6Class( # nolint
if (filtered) data() else data
},

#' @description
#' Returns whether the datasets in the object has undergone a reproducibility check.
#'
#' @return `logical`
#'
get_check = function() {
private$.check
},

#' @description
#' Gets metadata for a given dataset.
#'
Expand Down Expand Up @@ -375,34 +342,6 @@ FilteredData <- R6::R6Class( # nolint
invisible(self)
},

#' @description
#' Sets whether the datasets in the object have undergone a reproducibility check.
#'
#' @param check (`logical`) whether datasets have undergone reproducibility check
#'
#' @return (`self`)
#'
set_check = function(check) {
checkmate::assert_flag(check)
private$.check <- check
invisible(self)
},

#' @description
#' Sets the R preprocessing code for single dataset.
#'
#' @param code (`CodeClass`)\cr
#' preprocessing code that can be parsed to generate the unfiltered datasets
#'
#' @return (`self`)
#'
set_code = function(code) {
checkmate::assert_class(code, "CodeClass")
logger::log_trace("FilteredData$set_code setting code")
private$code <- code
invisible(self)
},

# Functions useful for restoring from another dataset ----

#' @description
Expand Down Expand Up @@ -1071,12 +1010,6 @@ FilteredData <- R6::R6Class( # nolint
# activate/deactivate filter panel
filter_panel_active = TRUE,

# whether the datasets had a reproducibility check
.check = FALSE,

# preprocessing code used to generate the unfiltered datasets as a string
code = NULL,

# `reactive` containing teal_slices that can be selected; only active in module-specific mode
available_teal_slices = NULL,

Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
plotly::plot_ly
shinycssloaders::withSpinner
shinyWidgets::pickerOptions
teal.data::datanames
teal.widgets::optionalSelectInput
}

Expand Down
6 changes: 3 additions & 3 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cloneable
Forkers
funder
Hoffmann
MultiAssayExperiment
UI
cloneable
funder
programmatically
repo
reproducibility
subclasses
subtype
UI
89 changes: 1 addition & 88 deletions man/FilteredData.Rd

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

61 changes: 0 additions & 61 deletions tests/testthat/test-FilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,6 @@ testthat::test_that("constructor accepts join_keys to be join_keys or NULL", {
)
})

testthat::test_that("constructor accepts code to be CodeClass or NULL", {
mockcodeclass <- R6::R6Class(classname = "CodeClass")
testthat::expect_no_error(
FilteredData$new(list(iris = list(dataset = iris)), code = mockcodeclass$new())
)
testthat::expect_no_error(
FilteredData$new(list(iris = list(dataset = iris)), code = NULL)
)
testthat::expect_error(
FilteredData$new(list(iris = list(dataset = iris)), code = list(), "Assertion on 'code' failed")
)
})

testthat::test_that("constructor accepts check to be a flag", {
testthat::expect_no_error(
FilteredData$new(list(iris = list(dataset = iris)), check = TRUE)
)
testthat::expect_error(
FilteredData$new(list(iris = list(dataset = iris)), check = NULL, "Assertion on 'check' failed")
)
testthat::expect_error(
FilteredData$new(list(iris = list(dataset = iris)), check = logical(0), "Assertion on 'check' failed")
)
})

testthat::test_that("FilteredData preserves the check field when check is TRUE", {
code <- teal.data:::CodeClass$new()$set_code("df_1 <- data.frame(x = 1:10)")

filtered_data <- FilteredData$new(
list("df_1" = list(dataset = data.frame(x = 1:10))),
code = code,
check = FALSE
)
testthat::expect_false(filtered_data$get_check())

filtered_data <- FilteredData$new(
list("df_1" = list(dataset = data.frame(x = 1:10))),
code = code,
check = TRUE
)
testthat::expect_true(filtered_data$get_check())
})


# datanames ----
testthat::test_that("filtered_data$datanames returns character vector of datasets names", {
dataset <- list(dataset = iris)
Expand Down Expand Up @@ -207,23 +163,6 @@ testthat::test_that("get_metadata returns metadata if dataset exists", {
})


# get_code ----
testthat::test_that("get_code returns the code passed to CodeClass$set_code", {
code <- teal.data:::CodeClass$new()
code$set_code("'preprocessing code'", "iris")
filtered_data <- FilteredData$new(
list(iris = list(dataset = head(iris))),
code = code
)
testthat::expect_equal(filtered_data$get_code(), "\"preprocessing code\"")
})

testthat::test_that("get_code returns a string when FilteredData has no code", {
filtered_data <- FilteredData$new(data_objects = list())
testthat::expect_identical(filtered_data$get_code(), "# No pre-processing code provided")
})


# get_call ----
testthat::test_that("get_call returns a NULL if no filters applied", {
datasets <- FilteredData$new(
Expand Down
Loading
Loading