Skip to content

Commit

Permalink
fix #30
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Jul 5, 2024
1 parent de5988b commit 31e68a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions R/as-cubble.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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))
}
}

Expand Down
13 changes: 9 additions & 4 deletions R/cubble-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 31e68a7

Please sign in to comment.