Skip to content

Commit

Permalink
Closes #1352. merge() handles ignores names in by argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Sep 23, 2015
1 parent 483d02a commit 5698f57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ merge.data.table <- function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FA
stop("A non-empty vector of column names for `by` is required.")
if (!all(by %in% intersect(colnames(x), colnames(y))))
stop("Elements listed in `by` must be valid column names in x and y")
by = unname(by)
by.x = by.y = by
}
# with i. prefix in v1.9.3, this goes away. Left here for now ...
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

3. `last()` dispatches `xts::last()` properly again, [#1347](https://github.com/Rdatatable/data.table/issues/1347). Thanks to @JoshuaUlrich for spotting and suggesting the fix.

4. `merge.data.table` ignores names when `by` argument is a named vector, [#1352](https://github.com/Rdatatable/data.table/issues/1352). Thanks @sebastian-c.

#### NOTES


Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -6960,6 +6960,12 @@ if (!"package:xts" %in% search()) {
test(1559.2, last(.xts(1:3,1:3)), .xts(1:3, 1:3)[3, ])
}

# fix for #1352
dt1 = data.table(a=1:5, b=6:10, c=11:15)
dt2 = data.table(a=3:6, b=8:11, d=1L)
by_cols = c(x="a", y="b")
test(1560, merge(dt1,dt2, by=by_cols, sort=FALSE), dt1[dt2, nomatch=0L, on=unname(by_cols)])

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


Expand Down

0 comments on commit 5698f57

Please sign in to comment.