From 98e6494ccd4b476a900bb831183a752c77b4f2ab Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 11 Oct 2019 13:13:01 +0200 Subject: [PATCH 1/2] Bugfixes in SelectorChecker() --- R/SelectorChecker.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/SelectorChecker.R b/R/SelectorChecker.R index c013dff..1bf2681 100644 --- a/R/SelectorChecker.R +++ b/R/SelectorChecker.R @@ -199,8 +199,8 @@ SelectorChecker <- function(selectors, var = NULL, return_indices = TRUE, if (!identical(class(var), class(selectors))) { stop("Class of provided selectors does not match class of 'var'.") } - candidates <- which(as.vector(var) == as.vector(selectors)) - if (length(candidates) == 0) { + candidates <- match(as.vector(selectors), as.vector(var)) + if (length(candidates) == 0 | any(is.na(candidates))) { stop("Selectors do not match values in 'var'.") } else if (length(candidates) != length(selectors)) { stop("Some selectors do not match values in 'var'.") -- GitLab From 31591cd71c58fcee0da4c3a7ca8234d1ca82cdfb Mon Sep 17 00:00:00 2001 From: aho Date: Tue, 15 Oct 2019 13:18:33 +0200 Subject: [PATCH 2/2] Add warning if not all files have the selectors assigned with characters --- R/Start.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/R/Start.R b/R/Start.R index bac9c66..21def44 100644 --- a/R/Start.R +++ b/R/Start.R @@ -953,9 +953,11 @@ debug <- TRUE dim = files_to_load) names(dim(sub_array_of_not_found_files)) <- known_dims j <- 1 + selector_indices_save <- vector('list', prod(files_to_load)) while (j <= prod(files_to_load)) { selector_indices <- which(sub_array_of_files_to_load == j, arr.ind = TRUE)[1, ] names(selector_indices) <- known_dims + selector_indices_save[[j]] <- selector_indices selectors <- sapply(1:length(known_dims), function (x) { vector_to_pick <- 1 @@ -1986,6 +1988,21 @@ print("-> THE INNER DIMENSION DOES NOT GO ACROSS ANY FILE DIMENSION OR IT DOES B chunks[[inner_dim]]['n_chunks'], inner_dim)] # The sub_array_of_indices now contains numeric indices of the values to be taken. + +#Check if all the files have the selectors assigned (e.g., region = 'Grnland') _20191015 +if (is.character(sub_array_of_selectors)) { + array_of_var_files_check <- vector('list', length(selector_indices)) + for (k in 1:length(selector_indices)) { + asdasd <- selector_indices[[k]] + array_of_var_files_check <- do.call('[', c(list(x = array_of_files_to_load), asdasd, list(drop = FALSE)))[j] + file_object <- file_opener(array_of_var_files_check) + var_values_check <- file_var_reader(NULL, file_object, NULL, var_to_read, synonims) + if (any(as.vector(var_values_check)[sub_array_of_indices] != sub_array_of_selectors)) { + .warning('Not all the files has correponding selectors. Check the selector attributes') + } + } +} + if (debug) { if (inner_dim %in% dims_to_check) { print("-> TRANSFORMATION REQUESTED?") -- GitLab