diff --git a/R/Start.R b/R/Start.R index d59e277ddf151340912d274458e0d573ea8102b5..56e9491e68bc689d8d0f1105ae2eb309dbc05130 100644 --- a/R/Start.R +++ b/R/Start.R @@ -1936,7 +1936,7 @@ Start <- function(..., # dim = indices/selectors, # If any of the dimensions comes without defining variable, then we read # the data dimensions. data_dims <- NULL - if (length(unlist(var_params[expected_inner_dims[[i]]])) < length(expected_inner_dims[[i]])) { +# if (length(unlist(var_params[expected_inner_dims[[i]]])) < length(expected_inner_dims[[i]])) { file_to_open <- file_path data_dims <- file_dim_reader(file_to_open, NULL, selectors_of_first_files_with_data[[i]], lapply(dat[[i]][['selectors']][expected_inner_dims[[i]]], '[[', 1), @@ -1944,7 +1944,7 @@ Start <- function(..., # dim = indices/selectors, # file_dim_reader returns dimension names as found in the file. # Need to translate accoridng to synonims: names(data_dims) <- replace_with_synonmins(data_dims, synonims) - } +# } if (is.numeric(largest_dims_length)) { # largest_dims_length is a named vector # Check if the names fit the inner dimension names @@ -1971,6 +1971,23 @@ Start <- function(..., # dim = indices/selectors, } # end if (largest_dims_length == TRUE) #////////////////////////////////////////////////// + # Some dimension is defined in Start() call but doesn't exist in data + if (!all(expected_inner_dims[[i]] %in% names(data_dims))) { + tmp <- expected_inner_dims[[i]][which(!expected_inner_dims[[i]] %in% names(data_dims))] + stop("Could not find the dimension '", tmp, "' in the file. Either ", + "change the dimension name in your request, adjust the ", + "parameter 'dim_names_in_files' or fix the dimension name in ", + "the file.\n", file_path) + } + # Not all the inner dims are defined in Start() call + if (!all(names(data_dims) %in% expected_inner_dims[[i]])) { + tmp <- names(data_dims)[which(!names(data_dims) %in% expected_inner_dims[[i]])] + if (data_dims[tmp] != 1) { + stop("The dimension '", tmp, "' is found in the file ", file_path, + " but not defined in the Start call.") + } + } + #/////////////////////////////////////////////////////////////////// # Transform the variables if needed and keep them apart. @@ -2282,13 +2299,7 @@ Start <- function(..., # dim = indices/selectors, } ## TODO HERE:: #- indices_of_first_files_with_data may change, because array is now extended - if (!(inner_dim %in% names(var_full_dims))) { - stop("Could not find the dimension '", inner_dim, "' in ", - "the file. Either change the dimension name in ", - "your request, adjust the parameter ", - "'dim_names_in_files' or fix the dimension name in ", - "the file.\n", file_path) - } + var_full_dims <- dim(var_with_selectors) } else if (((is.numeric(selector_array) || is.list(selector_array)) && selectors_are_indices) || (is.character(selector_array) && (length(selector_array) == 1) && (selector_array %in% c('all', 'first', 'last')) && @@ -2298,13 +2309,6 @@ Start <- function(..., # dim = indices/selectors, # Lines moved above for better performance. ##data_dims <- file_dim_reader(file_path, NULL, selectors_of_first_files_with_data[[i]], ## lapply(dat[[i]][['selectors']][expected_inner_dims[[i]]], '[[', 1)) - if (!(inner_dim %in% names(data_dims))) { - stop("Could not find the dimension '", inner_dim, "' in ", - "the file. Either change the dimension name in ", - "your request, adjust the parameter ", - "'dim_names_in_files' or fix the dimension name in ", - "the file.\n", file_path) - } } else { stop(paste0("Can not translate the provided selectors for '", inner_dim, "' to numeric indices. Provide numeric indices and a ", diff --git a/tests/testthat/test-Compute-transform_indices.R b/tests/testthat/test-Compute-transform_indices.R index 12c838db1dee32005a2d919830ff2e89b8000d8b..e482b21a1d28f90328dc03cb18f3851c1721b2a8 100644 --- a/tests/testthat/test-Compute-transform_indices.R +++ b/tests/testthat/test-Compute-transform_indices.R @@ -187,33 +187,33 @@ func <- function(x) { step <- Step(func, target_dims = 'time', output_dims = 'time') wf <- AddStep(exp, step) -#WRONG!!!!!!!!!! -#suppressWarnings( -#res_crop_T_1 <- Compute(wf, chunks = list(lon = 2)) -#) +#WRONG?????? +suppressWarnings( +res_crop_T_1 <- Compute(wf, chunks = list(lon = 2)) +) suppressWarnings( res_crop_T_2 <- Compute(wf, chunks = list(ensemble = 1)) ) -#WRONG!!!!!!!!!! -#suppressWarnings( -#res_crop_T_3 <- Compute(wf, chunks = list(lon = 3)) -#) +#WRONG????? +suppressWarnings( +res_crop_T_3 <- Compute(wf, chunks = list(lon = 3)) +) suppressWarnings( res_crop_T_4 <- Compute(wf, chunks = list(lat = 2)) ) -#expect_equal( -#res1$output1, -#res_crop_T_1$output1 -#) +expect_equal( +res1$output1, +res_crop_T_1$output1 +) expect_equal( res1$output1, res_crop_T_2$output1 ) -#expect_equal( -#res1$output1, -#res_crop_T_3$output1 -#) +expect_equal( +res1$output1, +res_crop_T_3$output1 +) expect_equal( res1$output1, res_crop_T_4$output1 diff --git a/tests/testthat/test-Compute-transform_values.R b/tests/testthat/test-Compute-transform_values.R index 0abd1b51d0d419e41db19d53b041d9e5768bf3c3..a8dae02ce6def77d14caa4cf7d94dc4666949470 100644 --- a/tests/testthat/test-Compute-transform_values.R +++ b/tests/testthat/test-Compute-transform_values.R @@ -290,33 +290,33 @@ func <- function(exp) { step <- Step(func, target_dims = 'sdate', output_dims = 'sdate') wf <- AddStep(exp, step) -#WRONG -#suppressWarnings( -#res_crop_T_1 <- Compute(wf, chunks = list(latitude = 2, longitude = 2))$output1 -#) +#WRONG? +suppressWarnings( +res_crop_T_1 <- Compute(wf, chunks = list(latitude = 2, longitude = 2))$output1 +) suppressWarnings( res_crop_T_2 <- Compute(wf, chunks = list(ensemble = 1))$output1 ) -#WRONG -#suppressWarnings( -#res_crop_T_3 <- Compute(wf, chunks = list(longitude = 3))$output1 -#) +#WRONG? +suppressWarnings( +res_crop_T_3 <- Compute(wf, chunks = list(longitude = 3))$output1 +) suppressWarnings( res_crop_T_4 <- Compute(wf, chunks = list(latitude = 3))$output1 ) -#expect_equal( -#res1, -#res_crop_T_1 -#) +expect_equal( +res1, +res_crop_T_1 +) expect_equal( res1, res_crop_T_2 ) -#expect_equal( -#res1, -#res_crop_T_3 -#) +expect_equal( +res1, +res_crop_T_3 +) expect_equal( res1, res_crop_T_4