File tree 5 files changed +29
-0
lines changed
5 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ Imports:
34
34
Rcpp,
35
35
wk (>= 0.6.0)
36
36
Suggests:
37
+ bit64,
37
38
testthat (>= 3.0.0),
38
39
vctrs
39
40
URL: https://r-spatial.github.io/s2/, https://github.com/r-spatial/s2, https://s2geometry.io/
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ S3method(as.character,s2_cell_union)
12
12
S3method(as.character,s2_geography)
13
13
S3method(as.list,s2_cell)
14
14
S3method(as_s2_cell,character)
15
+ S3method(as_s2_cell,integer64)
15
16
S3method(as_s2_cell,s2_cell)
16
17
S3method(as_s2_cell,s2_geography)
17
18
S3method(as_s2_cell,wk_xy)
Original file line number Diff line number Diff line change @@ -88,13 +88,31 @@ as_s2_cell.wk_xy <- function(x, ...) {
88
88
cpp_s2_cell_from_lnglat(as_s2_lnglat(x ))
89
89
}
90
90
91
+ # ' @rdname s2_cell
92
+ # ' @export
93
+ as_s2_cell.integer64 <- function (x , ... ) {
94
+ storage <- unclass(x )
95
+ storage [is.na(x )] <- NA_real_
96
+ new_s2_cell(storage )
97
+ }
98
+
91
99
# ' @rdname s2_cell
92
100
# ' @export
93
101
new_s2_cell <- function (x ) {
94
102
stopifnot(is.double(x ))
95
103
structure(x , class = c(" s2_cell" , " wk_vctr" ))
96
104
}
97
105
106
+ # registered in zzz.R
107
+ as.integer64.s2_cell <- function (x , ... ) {
108
+ # We store 64-bit integegers the same way bit64 does so we can just set the
109
+ # class attribute and propagate NA values in the way that bit64 expects them.
110
+ x_is_na <- is.na(x )
111
+ class(x ) <- " integer64"
112
+ x [x_is_na ] <- bit64 :: NA_integer64_
113
+ x
114
+ }
115
+
98
116
# ' @export
99
117
as.character.s2_cell <- function (x , ... ) {
100
118
cpp_s2_cell_to_string(x )
Original file line number Diff line number Diff line change 10
10
s3_register(" vctrs::vec_restore" , cls )
11
11
s3_register(" vctrs::vec_ptype_abbr" , cls )
12
12
}
13
+
14
+ s3_register(" bit64::as.integer64" , " s2_cell" )
13
15
}
14
16
15
17
s3_register <- function (generic , class , method = NULL ) {
Original file line number Diff line number Diff line change @@ -10,6 +10,13 @@ test_that("s2_cell class works", {
10
10
)
11
11
})
12
12
13
+ test_that(" s2_cell bit64::integer64 support works" , {
14
+ cells <- c(as_s2_cell(NA_character_ ), s2_cell_sentinel())
15
+ int64s <- bit64 :: as.integer64(cells )
16
+ expect_identical(int64s , bit64 :: as.integer64(c(NA , - 1 )))
17
+ expect_identical(as_s2_cell(int64s ), cells )
18
+ })
19
+
13
20
test_that(" invalid and sentinel values work as expected" , {
14
21
expect_false(s2_cell_is_valid(s2_cell_sentinel()))
15
22
expect_false(s2_cell_is_valid(s2_cell_invalid()))
You can’t perform that action at this time.
0 commit comments