Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions R/highlevel64.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally understood how the R code works, it's somewhat unexpected:

https://github.com/r-devel/r-svn/blob/0f7760a26a9381915a52609bc18fd776eee23a41/src/main/coerce.c#L1884

The C-level coercion asInteger() always needs to return a single int value, so its behavior differs from as.integer() which returns integer() when encountering NULL.

return(rep(nomatch, length(x)))
}
stopifnot(is.integer64(x))
table <- as.integer64(table)
cache_env <- cache(table)
Expand Down
2 changes: 1 addition & 1 deletion R/integer64.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-integer64.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Comment thread
MichaelChirico marked this conversation as resolved.
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))
})