From cd7506d8873ce3b7d8b511ef7cdd5ffb63f8c660 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 14 Feb 2025 16:52:46 +0100 Subject: [PATCH] tidy --- R/stars.R | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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) {