From 71b6ba08af518c293f44afc4a2e1ea82bb60af97 Mon Sep 17 00:00:00 2001 From: David Blodgett Date: Wed, 24 Apr 2024 16:25:50 -0500 Subject: [PATCH] use reordered dims properly for #680 --- R/ncdf.R | 2 +- tests/testthat/test-ncdf.R | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/R/ncdf.R b/R/ncdf.R index 7a977a56..56ff3042 100644 --- a/R/ncdf.R +++ b/R/ncdf.R @@ -183,7 +183,7 @@ read_ncdf = function(.x, ..., var = NULL, ncsub = NULL, curvilinear = character( # Create stars dimensions object - if(is.null(nc_dim <- dim(out_data[[1]]))) nc_dim <- dims$length + nc_dim <- dims$count dimensions <- create_dimensions(setNames(nc_dim, dims$name), raster) diff --git a/tests/testthat/test-ncdf.R b/tests/testthat/test-ncdf.R index 374a9428..0241cd14 100644 --- a/tests/testthat/test-ncdf.R +++ b/tests/testthat/test-ncdf.R @@ -313,9 +313,15 @@ test_that("axis attribute order -- see #680", { s2 <- suppressWarnings(stars::read_ncdf(file2)) - expect_equal(names(stars::st_dimensions(s2)), c("lon", "lat", "time")) + d <- stars::st_dimensions(s2) + + expect_equal(names(d), c("lon", "lat", "time")) + expect_equal(d$time$to, 9) + s3 <- suppressWarnings(stars::read_ncdf(file3)) expect_equal(names(stars::st_dimensions(s3)), c("lon", "lat", "time")) + + expect_equal(d$time$to, 9) })