Skip to content

Commit 8e0f62e

Browse files
committed
Return to range(x, ..., na.rm = FALSE) prototype for common speedup
The `range` generic doesn't separate out `x` and `...`, but splitting them out lets us easily check whether we can skip a potentially-slow `vec_c` operation to combine them.
1 parent fe32780 commit 8e0f62e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

R/type-vctr.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,10 @@ max.vctrs_vctr <- function(x, ..., na.rm = FALSE) {
620620
}
621621

622622
#' @export
623-
range.vctrs_vctr <- function(..., na.rm = FALSE) {
624-
x <- vec_c(...)
623+
range.vctrs_vctr <- function(x, ..., na.rm = FALSE) {
624+
if (dots_n(...) != 0L) {
625+
x <- vec_c(x, ...)
626+
}
625627

626628
if (vec_is_empty(x)) {
627629
return(vec_cast_or_na(c(Inf, -Inf), x))

tests/testthat/test-type-vctr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ test_that("`min` and `max` either combine `x` and `...` or abort (#1372)", {
659659
expect_snapshot(max(rep(x, 5), y), error = TRUE, cnd_class = TRUE)
660660
})
661661

662-
test_that("`range` combines `...` (#1372)", {
662+
test_that("`range` combines arguments as expected (#1372)", {
663663
x <- new_vctr(1)
664664
y <- new_vctr(3)
665665
z <- new_vctr(as.numeric(13:11))

0 commit comments

Comments
 (0)