diff --git a/NEWS.md b/NEWS.md index 27b20df269..2deaf72a28 100644 --- a/NEWS.md +++ b/NEWS.md @@ -189,6 +189,8 @@ 53. `fread` won't use `wget` for file:// input, [#1668](https://github.com/Rdatatable/data.table/issues/1668); thanks @MichaelChirico for FR&PR. + 54. `chmatch()` handles `nomatch = integer(0)` properly, [#1672](https://github.com/Rdatatable/data.table/issues/1672). + #### NOTES 1. Updated error message on invalid joins to reflect the new `on=` syntax, [#1368](https://github.com/Rdatatable/data.table/issues/1368). Thanks @MichaelChirico. diff --git a/R/data.table.R b/R/data.table.R index f065bac609..103cf2c15c 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -2458,7 +2458,7 @@ set <- function(x,i=NULL,j,value) # low overhead, loopable } chmatch <- function(x,table,nomatch=NA_integer_) - .Call(Cchmatchwrapper,x,table,as.integer(nomatch),FALSE) + .Call(Cchmatchwrapper,x,table,as.integer(nomatch[1L]),FALSE) # [1L] to fix #1672 "%chin%" <- function(x,table) { # TO DO if table has 'ul' then match to that diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 73c6b87295..86c3c64483 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -8809,6 +8809,9 @@ test(1667.1, capture.output(dcast(DT, id ~ rowid(id), value.var = "V1")), DT <- data.table(a = 1:4, id = 1:4, id = rep(1:4, 2), V1 = 8:1) test(1667.2, dcast(DT, id ~ rowid(id), value.var = "V1"), error = "data.table to cast") +# fix for #1672 +test(1668, chmatch(c("a","b"), c("a","c"), nomatch = integer()), c(1L, NA_integer_)) + ########################## # TODO: Tests involving GForce functions needs to be run with optimisation level 1 and 2, so that both functions are tested all the time.