diff --git a/R/CST_Subset.R b/R/CST_Subset.R index 2e69c1f9fe2d7de0d2d87170f1806d20d0b9737a..28c8498cbcb52cc984a37a21f189700fa7484fc8 100644 --- a/R/CST_Subset.R +++ b/R/CST_Subset.R @@ -87,7 +87,7 @@ CST_Subset <- function(x, along, indices, drop = FALSE, var_dim = NULL, # Adjust coordinates for (dimension in 1:length(along)) { dim_name <- along[dimension] - index <- indices[[dimension]] + index <- indices[dimension] # Only rename coordinates that have not been dropped if (dim_name %in% names(x$dims)) { # Subset coordinate by indices @@ -150,7 +150,7 @@ CST_Subset <- function(x, along, indices, drop = FALSE, var_dim = NULL, # Function to subset with attributes .subset_with_attrs <- function(x, ...) { args_subset <- list(...) - if (is.null(dim(x)) | length(dim(x)) == 1) { + if (any(is.null(dim(x)), length(dim(x)) == 1)) { l <- x[args_subset[['indices']][[1]]] } else { l <- ClimProjDiags::Subset(x, along = args_subset[['along']], diff --git a/tests/testthat/test-CST_Subset.R b/tests/testthat/test-CST_Subset.R index 9fc04b48408c654e40c13f3537a5daff387261f9..2a4fdd1f329f91ea3491b2f0f48e184ec635607f 100644 --- a/tests/testthat/test-CST_Subset.R +++ b/tests/testthat/test-CST_Subset.R @@ -50,6 +50,26 @@ test_that("2. Output checks: CST_Subset", { names(res1$coords), c("member", "ftime", "lon") ) + ## lat + expect_equal( + res1$coords$lat, + NULL + ) + ## lon + expect_equal( + as.vector(res1$coords$lon), + c(6, 7) + ) + ## sdate + expect_equal( + res1$coords$sdate, + NULL + ) + ## member + expect_equal( + as.vector(res1$coords$member), + c(1,2) + ) # Check attrs expect_equal( names(res1$attrs),