diff --git a/NEWS.md b/NEWS.md index c8cd96392f..8e4cd5b176 100644 --- a/NEWS.md +++ b/NEWS.md @@ -129,6 +129,7 @@ 31. Fixed a bug on Windows where `data.table`s containing non-UTF8 strings in `key`s were not properly sorted, [#2462](https://github.com/Rdatatable/data.table/issues/2462), [#1826](https://github.com/Rdatatable/data.table/issues/1826) and [StackOverflow](https://stackoverflow.com/questions/47599934/why-doesnt-r-data-table-support-well-for-non-ascii-keys-on-windows). Thanks to @shrektan for reporting and fixing. +32. `x.` prefixes during joins sometimes resulted in a "column not found" error. This is now fixed. Closes [#2313](https://github.com/Rdatatable/data.table/issues/2313). Thanks to @franknarf1 for the MRE. #### NOTES diff --git a/R/data.table.R b/R/data.table.R index 895649c724..6b1b33b9be 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1504,7 +1504,7 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) { if (length(xcols)) { # TODO add: if (length(alloc)==nrow(x)) stop("There is no need to deep copy x in this case") SDenv$.SDall = .Call(CsubsetDT,x,alloc,xcols) # must be deep copy when largest group is a subset - if (xdotcols) setattr(SDenv$.SDall, 'names', ansvars[seq_along(xcols)]) # now that we allow 'x.' prefix in 'j' + if (xdotcols) setattr(SDenv$.SDall, 'names', ansvars[xcolsAns]) # now that we allow 'x.' prefix in 'j', #2313 bug fix - [xcolsAns] SDenv$.SD = if (!length(othervars)) SDenv$.SDall else shallow(SDenv$.SDall, setdiff(ansvars, othervars)) } if (nrow(SDenv$.SDall)==0L) { diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 3da75efae9..a8d9e08159 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -11337,6 +11337,18 @@ test(1867.14, fread(f), data.table(V1=1:9, x=DT$x, y=DT$y, v=DT$v), warning="Add unlink(f) # test(1867.15, fread(testDir("iterations.txt"))) # #1416 TODO (trailing tabs on most but not at the beginning and a "-" intended to mean missing but taken as text column name) +# non equi joins bug fix #2313 +dt <- data.table( + patient.id = c(1L, 2L, 1L, 1L, 2L, 2L, 2L), + h.date = as.Date(c("2013/10/15", "2014/10/15", "2015/7/16", "2016/1/7", + "2015/12/20", "2015/12/25", "2016/2/10"))) +setorder(dt) +dt[, `:=`(start.date = h.date - 365, end.date = h.date)] +# This line below would error without this fix +ans <- dt[dt, on = .(patient.id, h.date >= start.date, h.date <= end.date), + .(patient.id, i.start.date, i.end.date, g = .GRP, .N, x.h.date), + by=.EACHI] +test(1868, "x.h.date" %in% names(ans), TRUE) ##########################