From 31e68a791c43986da333a4dae8ffdc3cde817955 Mon Sep 17 00:00:00 2001 From: huizezhang-sherry Date: Thu, 4 Jul 2024 23:33:41 -0500 Subject: [PATCH] fix #30 --- R/as-cubble.R | 9 +++++---- R/cubble-print.R | 13 +++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/R/as-cubble.R b/R/as-cubble.R index 30fa8474..4a083e02 100644 --- a/R/as-cubble.R +++ b/R/as-cubble.R @@ -63,7 +63,7 @@ as_cubble.data.frame <- function(data, key, index, coords, ...){ #' @rdname as_cubble #' @export -as_cubble.tbl_df <- function(data, key, index, coords, crs, ...) { +as_cubble.tbl_df <- function(data, key, index, coords, crs, dimensions, ...) { if (is_tsibble(data)){ key <- sym(tsibble::key_vars(data)) index <- sym(tsibble::index(data)) @@ -99,7 +99,9 @@ as_cubble.tbl_df <- function(data, key, index, coords, crs, ...) { data, key = as_name(key), index = as_name(index), coords = coords ) - if (!missing(crs)) res <- res |> make_spatial_sf(crs = crs) + #if (!missing(crs)) res <- res |> make_spatial_sf(crs = crs) + if (!missing(crs)) attr(res, "crs") <- crs + if (!missing(dimensions)) attr(res, "dimensions") <- dimensions return(res) @@ -199,8 +201,7 @@ as_cubble.stars <- function(data, key, index, coords, ...){ group_by(!!!map(longlat, sym)) |> mutate(id = dplyr::cur_group_id()) |> ungroup() |> - as_cubble(key = id, index = !!index, coords = longlat) |> - make_spatial_sf(crs = sf::st_crs(data)) + as_cubble(key = id, index = !!index, coords = longlat, dimension = stars::st_dimensions(data)) } } diff --git a/R/cubble-print.R b/R/cubble-print.R index cfed75df..7c691f83 100644 --- a/R/cubble-print.R +++ b/R/cubble-print.R @@ -39,13 +39,18 @@ tbl_sum.spatial_cubble_df <- function(x){ x <- as_tibble(x) |> sf::st_as_sf(coords = coord_vars) } - line2 <- glue::glue("[", paste0(sf::st_bbox(x), collapse = ", "), "]") - if (!x_is_sf) { - line2 <- glue::glue(line2, ", Missing CRS!") - } else{ + line2 <- glue::glue("[", paste0(round(sf::st_bbox(x), 2), collapse = ", "), "]") + if (x_is_sf) { line2 <- glue::glue(line2, ", {sf::st_crs(x, parameters = TRUE)$Name}") + } else if (!is.null(attr(x, "dimensions"))){ + line2 <- glue::glue(line2, ", {sf::st_crs(attr(x, 'dimensions'))$Name}") + } else{ + line2 <- glue::glue(line2, ", Missing CRS!") } + + + # header line 3: temporal variables all <- map(x$ts[[1]], tibble::type_sum) line3 <- glue::glue_collapse(