Skip to content

Commit

Permalink
Closes #698. not-join, X[!Y], ignores allow.cartesian argument as the…
Browse files Browse the repository at this point in the history
… result cannot exceed nrow(x).
  • Loading branch information
arunsrinivasan committed Jul 31, 2014
1 parent 39e8952 commit 1e49af9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,9 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
for (ii in resetifactor) set(i,j=ii,value=origi[[ii]])
if (mult=="all") {
if (!byjoin) {
irows = if (allLen1) f__ else vecseq(f__,len__,if(allow.cartesian)NULL else as.integer(max(nrow(x),nrow(i))))
# fix for #698. When notjoin=TRUE, don't worry about allow.cartesian. It'll generate all indices but will be taken care of
# in the if-condition below for 'byjoin'. Number of rows after that will never be > nrow(x). So, we're safe. No need to impose here.
irows = if (allLen1) f__ else vecseq(f__,len__,if(allow.cartesian || notjoin) NULL else as.integer(max(nrow(x),nrow(i))))
}
} else {
irows = if (mult=="first") f__ else f__+len__-1L
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ We moved from R-Forge to GitHub on 9 June 2014, including history.
37. `setDT` now provides a friendly error when attempted to change a variable to data.table by reference whose binding is locked (usually when the variable is within a package, ex: CO2). Closes [#475](https://github.com/Rdatatable/data.table/issues/475). Thanks to David Arenburg for filing the report [here](http://stackoverflow.com/questions/23361080/error-in-setdt-from-data-table-package) on SO.
38. `X[!Y]` where `X` and `Y` are both data.tables ignores 'allow.cartesian' argument, and rightly so because a not-join (or anti-join) cannot exceed nrow(x). Thanks to @fedyakov for spotting this. Closes [#698](https://github.com/Rdatatable/data.table/issues/698).
#### NOTES
1. Reminder: using `rolltolast` still works but since v1.9.2 now issues the following warning:
Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -4938,6 +4938,11 @@ test(1354, X[Y, val2 := i.val2, allow.cartesian=TRUE][, val1 := NULL][order(id)]
# Fix for #475, setDT(CO2) should error, as it's trying to modify the object whose binding is locked.
test(1355, setDT(CO2), error="Can not convert 'CO2' to data.table by reference because binding is locked.")

# Fix for #698. not join doesn't need to check for allow.cartesian=TRUE.
DT1 <- data.table(x=rep(1:3, each=3L), y=1:9, key="x")
DT2 <- data.table(x=rep(c(3L,1L), each=10), z=1L)
test(1356, DT1[!DT2], data.table(x=2L, y=4:6, key="x"))

##########################


Expand Down

0 comments on commit 1e49af9

Please sign in to comment.