Skip to content

Commit

Permalink
change to check to coordinates exist #23
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Jan 19, 2024
1 parent e63a8db commit bec07bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#' @seealso [make_temporal_tsibble]
#' @examples
#' climate_mel |> make_spatial_sf()
make_spatial_sf <- function(x, sfc = NULL, crs, silent = FALSE) {
stopifnot(is_cubble_spatial(x),
make_spatial_sf <- function(x, sfc = NULL, crs,
silent = FALSE) {
stopifnot(is_cubble_spatial(x),
is.null(sfc) || inherits(sfc, "sfc"),
missing(crs) || inherits(crs, "crs"),
all(c("long", "lat") %in% names(x)) || all(c("x", "y") %in% names(x)))
!is.null(coords(x)))
if (! requireNamespace("sf", quietly = TRUE))
stop("package sf required, please install it first")
if (is.null(sfc)) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-sf.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test_that("cubble works with sf", {
expect_snapshot(climate_mel |> make_spatial_sf())
expect_snapshot(climate_mel |> rename(x = long, y = lat) |> make_spatial_sf())
})

0 comments on commit bec07bc

Please sign in to comment.