From 7c081717ea47d8ec5f76de204cfd853a40c42070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ka=C5=82=C4=99dkowski?= <6959016+gogonzo@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:08:40 +0100 Subject: [PATCH] Introduce teal_data class (#470) --- R/FilteredData-utils.R | 10 ++++++++-- R/FilteredData.R | 4 ++-- R/FilteredDataset.R | 2 +- man/FilteredData.Rd | 7 ++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 73dd94fd4..0b15fcd63 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -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) { @@ -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) @@ -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) } diff --git a/R/FilteredData.R b/R/FilteredData.R index 193021b08..25ec85c4b 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -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, @@ -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, @@ -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 diff --git a/R/FilteredDataset.R b/R/FilteredDataset.R index 66866f5b6..0c8ce3f1c 100644 --- a/R/FilteredDataset.R +++ b/R/FilteredDataset.R @@ -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 diff --git a/man/FilteredData.Rd b/man/FilteredData.Rd index 5cba73af1..e4b6a91c1 100644 --- a/man/FilteredData.Rd +++ b/man/FilteredData.Rd @@ -425,7 +425,12 @@ Get keys for the dataset. \subsection{Method \code{set_dataset()}}{ Adds a dataset to this \code{FilteredData}. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FilteredData$set_dataset(data, dataname, metadata, label)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FilteredData$set_dataset( + data, + dataname, + metadata = attr(data, "metadata"), + label = attr(data, "label") +)}\if{html}{\out{
}} } \subsection{Arguments}{