From 7c1ef86b3ad793bdda91e4f997d375010ac9fafa Mon Sep 17 00:00:00 2001 From: huizezhang-sherry Date: Fri, 13 Sep 2024 10:23:35 -0500 Subject: [PATCH] #35 --- R/cubble-print.R | 40 +++++++++++++++++++----------- tests/testthat/test-cubble-print.R | 4 +++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/R/cubble-print.R b/R/cubble-print.R index 7c691f83..bfa1278b 100644 --- a/R/cubble-print.R +++ b/R/cubble-print.R @@ -33,28 +33,38 @@ tbl_sum.spatial_cubble_df <- function(x){ # header line 2 - print bbox - x_is_sf <- is_sf(x) - if (!x_is_sf) { - coord_vars <- coords(x) - x <- as_tibble(x) |> sf::st_as_sf(coords = coord_vars) - } - - 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}") + if (is_empty(x$ts)){ + line2 <- NULL } else{ - line2 <- glue::glue(line2, ", Missing CRS!") + x_is_sf <- is_sf(x) + if (!x_is_sf) { + coord_vars <- coords(x) + x <- as_tibble(x) |> sf::st_as_sf(coords = coord_vars) + } + + 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( - glue::glue("{names(all)} [{all}]"), sep = ", ") + if (is_empty(x$ts)) { + line3 <- NULL + } else{ + all <- map(x$ts[[1]], tibble::type_sum) + line3 <- glue::glue_collapse( + glue::glue("{names(all)} [{all}]"), sep = ", ") + } + c("cubble" = line1, "spatial" = line2, "temporal" = line3) diff --git a/tests/testthat/test-cubble-print.R b/tests/testthat/test-cubble-print.R index eb855533..809e9d2c 100644 --- a/tests/testthat/test-cubble-print.R +++ b/tests/testthat/test-cubble-print.R @@ -6,3 +6,7 @@ test_that("from issue 21", { expect_snapshot(a) }) + +test_that("issue 35",{ + expect_snapshot(climate_aus |> filter(name == "foo")) +})