diff --git a/R/NcReadDims.R b/R/NcReadDims.R index 660b4efe20e64d9194a22100846d7bb6831bfe5c..5d2d87cd395b7c13a6c569ca3b2567064bb75e82 100644 --- a/R/NcReadDims.R +++ b/R/NcReadDims.R @@ -52,8 +52,7 @@ NcReadDims <- function(file_to_read, var_names = NULL) { new_dim <- c(var = 1) found_dims <- c(new_dim, found_dims) if (!is.null(dims)) { - dims <- .MergeArrayDims(dims, found_dims) - dims <- pmax(dims[[1]], dims[[2]]) + dims <- .MergeArrayDims(dims, found_dims)[[3]] dims['var'] <- dims['var'] + 1 } else { dims <- found_dims diff --git a/R/Utils.R b/R/Utils.R index cc9b059ba9b5844e4446ed7552820299ea8b45be..fde2c95c2599850b35bb9f56c6c4b63714cf4990 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -131,6 +131,11 @@ # It expects as inputs two named numeric vectors, and it extends them # with dimensions of length 1 until an ordered common dimension # format is reached. +# The first output is dims1 extended with 1s. +# The second output is dims2 extended with 1s. +# The third output is a merged dimension vector. If dimensions with +# the same name are found in the two inputs, and they have a different +# length, the maximum is taken. .MergeArrayDims <- function(dims1, dims2) { new_dims1 <- c() new_dims2 <- c() @@ -158,7 +163,7 @@ new_dims1 <- c(new_dims1, dims_to_add) new_dims2 <- c(new_dims2, dims2) } - list(new_dims1, new_dims2) + list(new_dims1, new_dims2, pmax(new_dims1, new_dims2)) } # This function takes two named arrays and merges them, filling with