Skip to content

Commit

Permalink
#35
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Sep 13, 2024
1 parent 9678251 commit 7c1ef86
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
40 changes: 25 additions & 15 deletions R/cubble-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-cubble-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ test_that("from issue 21", {

expect_snapshot(a)
})

test_that("issue 35",{
expect_snapshot(climate_aus |> filter(name == "foo"))
})

0 comments on commit 7c1ef86

Please sign in to comment.