From f76f78845df43f99068f91031a4d1488c78c6a20 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Fri, 11 Aug 2023 11:34:10 +0200 Subject: [PATCH 01/13] commit 1 --- R/FilteredData-utils.R | 1 - R/FilteredData.R | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 73dd94fd4..85b7657b0 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -55,7 +55,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) 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 From 2b1a77ee5f81acaaf699b7c9d26a95d471601b13 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Tue, 15 Aug 2023 08:58:27 +0200 Subject: [PATCH 02/13] up --- NAMESPACE | 1 + R/FilteredData-utils.R | 30 +++++++++--------------------- man/FilteredData.Rd | 7 ++++++- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 082fe0b30..5bc0bbdbf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ S3method(init_filter_states,data.frame) S3method(init_filter_states,matrix) S3method(init_filtered_data,TealData) S3method(init_filtered_data,default) +S3method(init_filtered_data,tdata) S3method(init_filtered_dataset,MultiAssayExperiment) S3method(init_filtered_dataset,data.frame) S3method(print,teal_slice) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 85b7657b0..f18d1824c 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -26,31 +26,19 @@ init_filtered_data <- function(x, join_keys, code, check) { #' @keywords internal #' @export -init_filtered_data.TealData <- function(x, # nolint - join_keys = x$get_join_keys(), - code = x$get_code_class(), - check = x$get_check()) { - data_objects <- lapply( - x$get_datanames(), - function(dataname) { - dataset <- x$get_dataset(dataname) - list( - dataset = dataset$get_raw_data(), - metadata = dataset$get_metadata(), - label = dataset$get_dataset_label() - ) - } - ) - names(data_objects) <- x$get_datanames() - - init_filtered_data( - x = data_objects, - join_keys = join_keys, - code = code, +init_filtered_data.tdata <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint + checkmate::assert_class(code, "CodeClass", null.ok = TRUE) + checkmate::assert_class(join_keys, "JoinKeys") + checkmate::assert_flag(check) + FilteredData$new( + as.list(x@env), + join_keys = x@join_keys, + code = teal.data:::CodeClass$new(code = teal.code::get_code(x), dataname = teal.data::get_dataname(x)), check = check ) } + #' @keywords internal #' @export init_filtered_data.default <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint 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}{ From 450ddc001cba62d73c60bc2951c981c2a38a6084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ka=C5=82=C4=99dkowski?= Date: Thu, 17 Aug 2023 07:36:18 +0200 Subject: [PATCH 03/13] fix --- R/FilteredData-utils.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index f18d1824c..abf06c707 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -33,7 +33,10 @@ init_filtered_data.tdata <- function(x, join_keys = teal.data::join_keys(), code FilteredData$new( as.list(x@env), join_keys = x@join_keys, - code = teal.data:::CodeClass$new(code = teal.code::get_code(x), dataname = teal.data::get_dataname(x)), + code = teal.data:::CodeClass$new( + code = paste(teal.code::get_code(x), collapse = "\n"), + dataname = teal.data::get_dataname(x) + ), check = check ) } From a8dd3fdef3cb566636b68e398cdeecc16301e4e5 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Fri, 29 Sep 2023 15:21:52 +0200 Subject: [PATCH 04/13] tdata -> teal_data --- R/FilteredData-utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index abf06c707..8e8677981 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -26,7 +26,7 @@ init_filtered_data <- function(x, join_keys, code, check) { #' @keywords internal #' @export -init_filtered_data.tdata <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint +init_filtered_data.teal_data <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint checkmate::assert_class(code, "CodeClass", null.ok = TRUE) checkmate::assert_class(join_keys, "JoinKeys") checkmate::assert_flag(check) From 79d756e5ae53c44dcbd32df141ebd8ebff01748b Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Mon, 2 Oct 2023 09:26:00 +0200 Subject: [PATCH 05/13] export method for teal_data --- NAMESPACE | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 5bc0bbdbf..fc8f4bc57 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,9 +21,8 @@ S3method(init_filter_states,MultiAssayExperiment) S3method(init_filter_states,SummarizedExperiment) S3method(init_filter_states,data.frame) S3method(init_filter_states,matrix) -S3method(init_filtered_data,TealData) S3method(init_filtered_data,default) -S3method(init_filtered_data,tdata) +S3method(init_filtered_data,teal_data) S3method(init_filtered_dataset,MultiAssayExperiment) S3method(init_filtered_dataset,data.frame) S3method(print,teal_slice) From c1d082c5bfe8873f35f6f29570e57f3fe4ae55fb Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Wed, 4 Oct 2023 14:36:43 +0200 Subject: [PATCH 06/13] creaate FilteredData basing only on @datanames --- R/FilteredData-utils.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 8e8677981..279227655 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -30,13 +30,17 @@ init_filtered_data.teal_data <- function(x, join_keys = teal.data::join_keys(), checkmate::assert_class(code, "CodeClass", null.ok = TRUE) checkmate::assert_class(join_keys, "JoinKeys") checkmate::assert_flag(check) + datanames <- x@datanames FilteredData$new( - as.list(x@env), + as.list(x@env)[datanames], join_keys = x@join_keys, + + # todo: to be removed soon https://github.com/insightsengineering/teal.slice/issues/471 code = teal.data:::CodeClass$new( code = paste(teal.code::get_code(x), collapse = "\n"), dataname = teal.data::get_dataname(x) ), + # todo: to remove check = check ) } From 16df8c46d4407b8cfcf848a57a6b7d02fd31f727 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Wed, 4 Oct 2023 14:51:50 +0200 Subject: [PATCH 07/13] deprecate old constructor based on TealData --- DESCRIPTION | 1 + NAMESPACE | 1 + R/FilteredData-utils.R | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 07198853c..56e5309f9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,6 +45,7 @@ Imports: shinycssloaders (>= 1.0.0), shinyjs, shinyWidgets (>= 0.6.2), + teal.code (>= 0.4.1), teal.data (>= 0.3.0), teal.logger (>= 0.1.1), teal.widgets (>= 0.4.0) diff --git a/NAMESPACE b/NAMESPACE index fc8f4bc57..13b43a3f1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,7 @@ S3method(init_filter_states,MultiAssayExperiment) S3method(init_filter_states,SummarizedExperiment) S3method(init_filter_states,data.frame) S3method(init_filter_states,matrix) +S3method(init_filtered_data,TealData) S3method(init_filtered_data,default) S3method(init_filtered_data,teal_data) S3method(init_filtered_dataset,MultiAssayExperiment) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 279227655..89757407a 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -24,6 +24,39 @@ init_filtered_data <- function(x, join_keys, code, check) { UseMethod("init_filtered_data") } +#' @keywords internal +#' @export +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' + )" + ) + data_objects <- lapply( + x$get_datanames(), + function(dataname) { + dataset <- x$get_dataset(dataname) + list( + dataset = dataset$get_raw_data(), + metadata = dataset$get_metadata(), + label = dataset$get_dataset_label() + ) + } + ) + names(data_objects) <- x$get_datanames() + + init_filtered_data( + x = data_objects, + join_keys = join_keys, + code = code, + check = check + ) +} + #' @keywords internal #' @export init_filtered_data.teal_data <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint From 9d5d868d6074c9f374f8c3210bdba5082bb070dc Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Fri, 6 Oct 2023 08:22:25 +0200 Subject: [PATCH 08/13] remove constructor for teal_data --- R/FilteredData-utils.R | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 89757407a..90a2904ba 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -33,7 +33,8 @@ init_filtered_data.TealData <- function(x, # nolint lifecycle::deprecate_warn( when = "0.4.1", "init_filtered_data( - x = 'constructor based on TealData is deprecated and will be removed soon' + 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( @@ -57,28 +58,6 @@ init_filtered_data.TealData <- function(x, # nolint ) } -#' @keywords internal -#' @export -init_filtered_data.teal_data <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint - checkmate::assert_class(code, "CodeClass", null.ok = TRUE) - checkmate::assert_class(join_keys, "JoinKeys") - checkmate::assert_flag(check) - datanames <- x@datanames - FilteredData$new( - as.list(x@env)[datanames], - join_keys = x@join_keys, - - # todo: to be removed soon https://github.com/insightsengineering/teal.slice/issues/471 - code = teal.data:::CodeClass$new( - code = paste(teal.code::get_code(x), collapse = "\n"), - dataname = teal.data::get_dataname(x) - ), - # todo: to remove - check = check - ) -} - - #' @keywords internal #' @export init_filtered_data.default <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint From 550cec597a6718634314b73c0394d1c264cef7f1 Mon Sep 17 00:00:00 2001 From: vedhav Date: Mon, 9 Oct 2023 15:54:15 +0530 Subject: [PATCH 09/13] chore: fix deprecation message --- R/FilteredData-utils.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 90a2904ba..62ed4dbc9 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -33,8 +33,8 @@ init_filtered_data.TealData <- function(x, # nolint 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. + 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( From 39746f58faff984394e8addc839634d7d531111e Mon Sep 17 00:00:00 2001 From: vedhav Date: Mon, 9 Oct 2023 16:08:05 +0530 Subject: [PATCH 10/13] chore: rebuild namespace and remove undeclared method --- NAMESPACE | 1 - 1 file changed, 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 13b43a3f1..082fe0b30 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,7 +23,6 @@ S3method(init_filter_states,data.frame) S3method(init_filter_states,matrix) S3method(init_filtered_data,TealData) S3method(init_filtered_data,default) -S3method(init_filtered_data,teal_data) S3method(init_filtered_dataset,MultiAssayExperiment) S3method(init_filtered_dataset,data.frame) S3method(print,teal_slice) From a78ffaada5c91251e2f497c77aefcd76f05b38fd Mon Sep 17 00:00:00 2001 From: vedhav Date: Mon, 9 Oct 2023 16:38:50 +0530 Subject: [PATCH 11/13] chore: remove teal.code as a direct dependency --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 56e5309f9..07198853c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,6 @@ Imports: shinycssloaders (>= 1.0.0), shinyjs, shinyWidgets (>= 0.6.2), - teal.code (>= 0.4.1), teal.data (>= 0.3.0), teal.logger (>= 0.1.1), teal.widgets (>= 0.4.0) From a7d9a18964393a8d06658da7a53dfc0b78c14632 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Mon, 30 Oct 2023 14:01:11 +0100 Subject: [PATCH 12/13] :face_palm: --- R/FilteredData-utils.R | 2 +- R/FilteredDataset.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 62ed4dbc9..43a4f299d 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -86,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") checkmate::assert_character(dataset_args[["label"]], null.ok = TRUE, min.len = 0, max.len = 1) } diff --git a/R/FilteredDataset.R b/R/FilteredDataset.R index 66866f5b6..564f899b8 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(dataset_args[["metadata"]], names = "named") logger::log_trace("Instantiating { class(self)[1] }, dataname: { dataname }") private$dataset <- dataset From 3d176e38cb60cba2356c8e73c486af9ddfdf0e38 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Mon, 30 Oct 2023 14:16:31 +0100 Subject: [PATCH 13/13] checks --- R/FilteredData-utils.R | 2 +- R/FilteredDataset.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/FilteredData-utils.R b/R/FilteredData-utils.R index 43a4f299d..0b15fcd63 100644 --- a/R/FilteredData-utils.R +++ b/R/FilteredData-utils.R @@ -86,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")) - checkmate::assert_list(dataset_args[["metadata"]], names = "named") + 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/FilteredDataset.R b/R/FilteredDataset.R index 564f899b8..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) - checkmate::assert_list(dataset_args[["metadata"]], names = "named") + checkmate::assert_list(metadata, names = "named", null.ok = TRUE) logger::log_trace("Instantiating { class(self)[1] }, dataname: { dataname }") private$dataset <- dataset