From 558e3b802ed83bdff57badf3dcc389ec2b9a4b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:29:56 +0100 Subject: [PATCH 1/2] fix: forces exact match on attribute to avoid problems (CO2) --- NEWS.md | 4 ++++ R/FilteredDataset-utils.R | 16 ++++++++-------- man/init_filtered_dataset.Rd | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index cae382621..2dfe04525 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,10 @@ * `set_filter_state` no longer accepts a nested list. Use `teal_slices()` and `teal_slice()` instead. * Renamed `FilteredDataset` subclass that handles `data.frame`s from `DefaultFilteredDataset` to `DataframeFilteredDataset`. Added new class `DefaultFilteredDataset` that will store any type of object. Filtering will is not supported. +### Bug fixes + +* Performs an exact match on `init_filtered_dataset` when determining the default label of a dataset. + ### Miscellaneous * Specified minimal version of package dependencies. diff --git a/R/FilteredDataset-utils.R b/R/FilteredDataset-utils.R index afbda9a3e..87ab2f61a 100644 --- a/R/FilteredDataset-utils.R +++ b/R/FilteredDataset-utils.R @@ -82,25 +82,25 @@ #' } #' @keywords internal #' @export -init_filtered_dataset <- function(dataset, # nolint +init_filtered_dataset <- function(dataset, dataname, keys = character(0), parent_name = character(0), parent = reactive(dataset), join_keys = character(0), - label = attr(dataset, "label")) { + label = attr(dataset, "label", exact = TRUE)) { UseMethod("init_filtered_dataset") } #' @keywords internal #' @export -init_filtered_dataset.data.frame <- function(dataset, # nolint +init_filtered_dataset.data.frame <- function(dataset, dataname, keys = character(0), parent_name = character(0), parent = NULL, join_keys = character(0), - label = attr(dataset, "label")) { + label = attr(dataset, "label", exact = TRUE)) { DataframeFilteredDataset$new( dataset = dataset, dataname = dataname, @@ -114,13 +114,13 @@ init_filtered_dataset.data.frame <- function(dataset, # nolint #' @keywords internal #' @export -init_filtered_dataset.MultiAssayExperiment <- function(dataset, # nolint +init_filtered_dataset.MultiAssayExperiment <- function(dataset, dataname, keys = character(0), parent_name, # ignored parent, # ignored join_keys, # ignored - label = attr(dataset, "label")) { + label = attr(dataset, "label", exact = TRUE)) { if (!requireNamespace("MultiAssayExperiment", quietly = TRUE)) { stop("Cannot load MultiAssayExperiment - please install the package or restart your session.") } @@ -134,13 +134,13 @@ init_filtered_dataset.MultiAssayExperiment <- function(dataset, # nolint #' @keywords internal #' @export -init_filtered_dataset.default <- function(dataset, # nolint +init_filtered_dataset.default <- function(dataset, dataname, keys, # ignored parent_name, # ignored parent, # ignored join_keys, # ignored - label = attr(dataset, "label")) { + label = attr(dataset, "label", exact = TRUE)) { DefaultFilteredDataset$new( dataset = dataset, dataname = dataname, diff --git a/man/init_filtered_dataset.Rd b/man/init_filtered_dataset.Rd index 7ef39b87d..36f1e3118 100644 --- a/man/init_filtered_dataset.Rd +++ b/man/init_filtered_dataset.Rd @@ -11,7 +11,7 @@ init_filtered_dataset( parent_name = character(0), parent = reactive(dataset), join_keys = character(0), - label = attr(dataset, "label") + label = attr(dataset, "label", exact = TRUE) ) } \arguments{ From 5d9e0c559c673dae133804cc39126c45e5d738c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:40:57 +0100 Subject: [PATCH 2/2] fix: extend fix to other occurences of label --- NEWS.md | 2 +- R/FilterState.R | 2 +- R/FilterStateChoices.R | 2 +- R/FilteredDataset.R | 2 +- man/FilteredDataset.Rd | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2dfe04525..6cf42daa5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,7 +14,7 @@ ### Bug fixes -* Performs an exact match on `init_filtered_dataset` when determining the default label of a dataset. +* Performs an exact match when determining the default label of a dataset from attributes. ### Miscellaneous diff --git a/R/FilterState.R b/R/FilterState.R index 2beea08c6..87f71b9b8 100644 --- a/R/FilterState.R +++ b/R/FilterState.R @@ -96,7 +96,7 @@ FilterState <- R6::R6Class( # nolint if (is.null(isolate(slice$keep_na)) && anyNA(x)) slice$keep_na <- TRUE private$teal_slice <- slice # Obtain variable label. - varlabel <- attr(x, "label") + varlabel <- attr(x, "label", exact = TRUE) # Display only when different from varname. private$varlabel <- if (is.null(varlabel) || identical(varlabel, private$get_varname())) { diff --git a/R/FilterStateChoices.R b/R/FilterStateChoices.R index 5ac4ca7fc..963ce93b8 100644 --- a/R/FilterStateChoices.R +++ b/R/FilterStateChoices.R @@ -159,7 +159,7 @@ ChoicesFilterState <- R6::R6Class( # nolint x_factor <- if (!is.factor(x)) { structure( factor(as.character(x), levels = as.character(sort(unique(x)))), - label = attr(x, "label") + label = attr(x, "label", exact = TRUE) ) } else { x diff --git a/R/FilteredDataset.R b/R/FilteredDataset.R index 679fcc3f4..0b2e37748 100644 --- a/R/FilteredDataset.R +++ b/R/FilteredDataset.R @@ -29,7 +29,7 @@ FilteredDataset <- R6::R6Class( # nolint #' #' @return Object of class `FilteredDataset`, invisibly. #' - initialize = function(dataset, dataname, keys = character(0), label = attr(dataset, "label")) { + initialize = function(dataset, dataname, keys = character(0), label = attr(dataset, "label", exact = TRUE)) { logger::log_trace("Instantiating { class(self)[1] }, dataname: { dataname }") # dataset assertion in child classes diff --git a/man/FilteredDataset.Rd b/man/FilteredDataset.Rd index 3dc5b1744..124477067 100644 --- a/man/FilteredDataset.Rd +++ b/man/FilteredDataset.Rd @@ -45,7 +45,7 @@ Initializes this \code{FilteredDataset} object. dataset, dataname, keys = character(0), - label = attr(dataset, "label") + label = attr(dataset, "label", exact = TRUE) )}\if{html}{\out{}} }