diff --git a/R/highlevel64.R b/R/highlevel64.R index ab6ee8d..eb73517 100644 --- a/R/highlevel64.R +++ b/R/highlevel64.R @@ -1355,6 +1355,12 @@ optimizer64 <- function(nsmall=2L^16L, #' @keywords manip logic #' @export match.integer64 <- function(x, table, nomatch = NA_integer_, nunique=NULL, method=NULL, ...) { + # trivial cases for zero length input + if (!length(x)) return(integer()) + if (!length(table)) { + nomatch = as.integer(c(nomatch, NA_integer_)[1L]) + return(rep(nomatch, length(x))) + } stopifnot(is.integer64(x)) table <- as.integer64(table) cache_env <- cache(table) diff --git a/R/integer64.R b/R/integer64.R index f8eb4f8..46c70a1 100644 --- a/R/integer64.R +++ b/R/integer64.R @@ -593,7 +593,7 @@ binattr <- function(e1, e2) { if (length(d1)) { if (length(d2)) { if (!identical(dim(e1), dim(e2))) - stop("non-conformable arrays") + stop(gettext("non-conformable arrays", domain="R")) } else { if (n2 > n1 && n1) stop("length(e2) does not match dim(e1)") diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index ecdc9eb..c66d8d3 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -482,3 +482,14 @@ test_that("anyNA method", { expect_identical(anyNA(as.integer64(c(NA, NA))), anyNA(c(NA, NA))) expect_identical(anyNA(integer64()), anyNA(integer())) }) + + +test_that("match works with zero length input", { + x32 = 1:10 + x64 = as.integer64(1:10) + expect_identical(match(x64, integer()), match(x32, integer())) + expect_identical(match(x64, integer(), nomatch=NULL), match(x32, integer(), nomatch=NULL)) + expect_identical(match(x64, integer(), nomatch=integer()), match(x32, integer(), nomatch=integer())) + expect_identical(match(x64, integer(), nomatch=10L), match(x32, integer(), nomatch=10L)) + expect_identical(match(integer(), x64), match(integer(), x32)) +})