stars
stars copied to clipboard
Cannot convert array to stars if only some dimensions are named
I had an array with only one dimension named and I was getting an error converting it to a stars object. After some digging, I realized it was because I only had one dimension named. It looks like st_as_stars
works if all the dimensions are named, as well as if the dimensions are not named, but does not work if only one dimension is named.
ar <- array(runif(27), dim=c(3, 3, 3))
#no dimnames, works
stars_object <- st_as_stars(ar)
#full dimnames, also works
dimnames(ar) <- list(d1=c('a', 'b', 'c'), d2=c('a', 'b', 'c'), d3=c('a', 'b', 'c'))
stars_object <- st_as_stars(ar)
#partial dimnames, fails
dimnames(ar) <- list(NULL, NULL, d3=c('a', 'b', 'c'))
stars_object <- st_as_stars(ar)
Kind of a small thing, but it would be nice if stars was flexible enough to handle these cases.