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..273305f5 100644 --- a/tests/testthat/test-ncdf.R +++ b/tests/testthat/test-ncdf.R @@ -313,9 +313,17 @@ 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")) + d <- stars::st_dimensions(s2) + + expect_equal(names(d), c("lon", "lat", "time")) + + expect_equal(d$time$to, 9) })