From b3ecb311f6344572f8a7b5896cc6147728a168b2 Mon Sep 17 00:00:00 2001 From: Arun Srinivasan Date: Tue, 27 Jan 2015 14:10:14 +0100 Subject: [PATCH] Adjusted #1010 fix to account for roll="nearest". Added test. --- R/data.table.R | 4 ++-- inst/tests/tests.Rraw | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/data.table.R b/R/data.table.R index b832a8370..4d76b55d2 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1066,7 +1066,7 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) { keylen = which.first(!key(x) %chin% ansvars)-1L if (is.na(keylen)) keylen = length(key(x)) if (keylen > length(rightcols) && !.Call(CisOrderedSubset, irows, nrow(x))) keylen = length(rightcols) - if (keylen && ((is.data.table(i) && haskey(i)) || is.logical(i) || (.Call(CisOrderedSubset, irows, nrow(x)) && (!roll || length(irows) == 1L)))) # see #1010. don't set key when i has no key, but irows is ordered and roll != FALSE + if (keylen && ((is.data.table(i) && haskey(i)) || is.logical(i) || (.Call(CisOrderedSubset, irows, nrow(x)) && ((roll == FALSE) || length(irows) == 1L)))) # see #1010. don't set key when i has no key, but irows is ordered and roll != FALSE setattr(ans,"sorted",head(key(x),keylen)) } setattr(ans, "class", class(x)) # fix for #5296 @@ -1177,7 +1177,7 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) { byval = i bynames = head(key(x),length(leftcols)) allbyvars = NULL - bysameorder = haskey(i) || (is.sorted(f__) && (!roll || length(f__) == 1L)) # Fix for #1010 + bysameorder = haskey(i) || (is.sorted(f__) && ((roll == FALSE) || length(f__) == 1L)) # Fix for #1010 ## 'av' correct here ?? *** TO DO *** xjisvars = intersect(av, names(x)[rightcols]) # no "x." for xvars. # if 'get' is in 'av' use all cols in 'i', fix for bug #5443 diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 1abe98166..3683f2dfc 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -5832,6 +5832,7 @@ test(1469.2, key(DT[J(c(2,0)), .(x,y), roll=TRUE]), NULL) test(1469.3, key(DT[J(c(2,0)), y, roll=TRUE, by=.EACHI]), NULL) test(1469.4, key(DT[J(c(2,0))]), NULL) test(1469.5, key(DT[SJ(c(2,0)), roll=TRUE]), "x") +test(1469.6, key(DT[J(c(2,0)), roll="nearest"]), NULL) # 1007 fix, dealing with Inf and -Inf correctly in rolling joins. DT = data.table(x=c(-Inf, 3, Inf), y=1:3, key="x")