Skip to content

support zero length input in match.integer64#191

Merged
MichaelChirico merged 4 commits intor-lib:mainfrom
hcirellu:edge_case_match
Nov 13, 2025
Merged

support zero length input in match.integer64#191
MichaelChirico merged 4 commits intor-lib:mainfrom
hcirellu:edge_case_match

Conversation

@hcirellu
Copy link
Copy Markdown
Collaborator

@hcirellu hcirellu commented Nov 13, 2025

Zero length input for x and table to match.integer64 should result in consistent results as match with integer.

Closes #190

Comment thread tests/testthat/test-integer64.R Outdated
Comment thread tests/testthat/test-integer64.R
Comment thread R/highlevel64.R Outdated
Comment thread R/highlevel64.R
# 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.

@MichaelChirico MichaelChirico changed the title support zero length input in match.integer64 (#190) support zero length input in match.integer64 Nov 13, 2025
@MichaelChirico MichaelChirico merged commit 0f1e0e8 into r-lib:main Nov 13, 2025
10 checks passed
@MichaelChirico
Copy link
Copy Markdown
Collaborator

Thanks!

Just minor points about GitHub itself:

@hcirellu hcirellu deleted the edge_case_match branch November 13, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

match.integer64 does not support zero length input

2 participants