diff --git a/R/stars.R b/R/stars.R index f0ec6446..005cbc43 100644 --- a/R/stars.R +++ b/R/stars.R @@ -473,15 +473,11 @@ st_coordinates.dimensions = function(x, ...) { #' @param add_coordinates logical; if `TRUE`, columns with dimension values preceed the array values, #' otherwise they are omitted as.data.frame.stars = function(x, ..., add_max = FALSE, center = NA, add_coordinates = TRUE) { - if (add_coordinates) { - coords = st_coordinates(x, add_max = add_max, center = center, ...) - setNames( - data.frame(coords, lapply(x, function(y) structure(y, dim = NULL))), - c(names(coords), names(x)) - ) - } + df = setNames(as.data.frame(lapply(x, function(y) structure(y, dim = NULL))), names(x)) + if (add_coordinates) + cbind(st_coordinates(x, add_max = add_max, center = center, ...), df) else - setNames(as.data.frame(lapply(x, function(y) structure(y, dim = NULL))), names(x)) + df } add_units = function(x) {