Skip to content

Commit cb918cb

Browse files
committed
fix rep() with zero-length s2_xptr vectors
1 parent a79bf1c commit cb918cb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

R/s2-xptr.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ validate_s2_xptr <- function(x) {
5454

5555
#' @export
5656
rep.s2_xptr <- function(x, ...) {
57-
new_s2_xptr(NextMethod(), class(x))
57+
if (length(x) == 0) {
58+
new_s2_xptr(list(), class(x))
59+
} else {
60+
new_s2_xptr(NextMethod(), class(x))
61+
}
5862
}
5963

6064
#' @method rep_len s2_xptr

tests/testthat/test-s2-xptr.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ test_that("s2_xptr validation works", {
2020
})
2121

2222
test_that("s2_xptr subsetting and concatenation work", {
23+
expect_length(rep(new_s2_xptr(list()), 10), 0)
24+
2325
xptr <- new_s2_xptr(list(NULL, NULL))
2426
expect_identical(xptr[1], new_s2_xptr(list(NULL)))
2527
expect_identical(xptr[[1]], xptr[1])

0 commit comments

Comments
 (0)