Skip to content

Commit

Permalink
Introduce teal_data class (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo authored Oct 30, 2023
1 parent 686f1f7 commit 7c08171
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
10 changes: 8 additions & 2 deletions R/FilteredData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ init_filtered_data.TealData <- function(x, # nolint
join_keys = x$get_join_keys(),
code = x$get_code_class(),
check = x$get_check()) {
lifecycle::deprecate_warn(
when = "0.4.1",
"init_filtered_data(
x = 'constructor based on TealData is deprecated and will be removed soon.
Please use generic init_filtered_data and specify all arguments directly.'
)"
)
data_objects <- lapply(
x$get_datanames(),
function(dataname) {
Expand All @@ -55,7 +62,6 @@ init_filtered_data.TealData <- function(x, # nolint
#' @export
init_filtered_data.default <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint
checkmate::assert_list(x, any.missing = FALSE, names = "unique")
mapply(validate_dataset_args, x, names(x))
checkmate::assert_class(code, "CodeClass", null.ok = TRUE)
checkmate::assert_class(join_keys, "JoinKeys")
checkmate::assert_flag(check)
Expand All @@ -80,7 +86,7 @@ validate_dataset_args <- function(dataset_args, dataname) {

checkmate::assert_subset(names(dataset_args), choices = allowed_names)
checkmate::assert_multi_class(dataset_args[["dataset"]], classes = c("data.frame", "MultiAssayExperiment"))
teal.data::validate_metadata(dataset_args[["metadata"]])
checkmate::assert_list(dataset_args[["metadata"]], names = "named", null.ok = TRUE)
checkmate::assert_character(dataset_args[["label"]], null.ok = TRUE, min.len = 0, max.len = 1)
}

Expand Down
4 changes: 2 additions & 2 deletions R/FilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ FilteredData <- R6::R6Class( # nolint

for (dataname in ordered_datanames) {
ds_object <- data_objects[[dataname]]
validate_dataset_args(ds_object, dataname)
if (inherits(ds_object, c("data.frame", "MultiAssayExperiment"))) {
self$set_dataset(
data = ds_object,
Expand All @@ -104,6 +103,7 @@ FilteredData <- R6::R6Class( # nolint
} else {
# custom support for TealData object which pass metadata and label also
# see init_filtered_data.TealData
validate_dataset_args(ds_object, dataname)
self$set_dataset(
data = ds_object$dataset,
dataname = dataname,
Expand Down Expand Up @@ -327,7 +327,7 @@ FilteredData <- R6::R6Class( # nolint
#' Label to describe the dataset
#' @return (`self`) invisibly this `FilteredData`
#'
set_dataset = function(data, dataname, metadata, label) {
set_dataset = function(data, dataname, metadata = attr(data, "metadata"), label = attr(data, "label")) {
logger::log_trace("FilteredData$set_dataset setting dataset, name: { dataname }")
# to include it nicely in the Show R Code;
# the UI also uses `datanames` in ids, so no whitespaces allowed
Expand Down
2 changes: 1 addition & 1 deletion R/FilteredDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FilteredDataset <- R6::R6Class( # nolint
check_simple_name(dataname)
checkmate::assert_character(keys, any.missing = FALSE)
checkmate::assert_character(label, null.ok = TRUE)
teal.data::validate_metadata(metadata)
checkmate::assert_list(metadata, names = "named", null.ok = TRUE)

logger::log_trace("Instantiating { class(self)[1] }, dataname: { dataname }")
private$dataset <- dataset
Expand Down
7 changes: 6 additions & 1 deletion man/FilteredData.Rd

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

0 comments on commit 7c08171

Please sign in to comment.