Skip to content

Commit

Permalink
Closes #1626. rbind coerces non-list i/p to data.table, then calls rb…
Browse files Browse the repository at this point in the history
…indlist.
  • Loading branch information
arunsrinivasan committed Jul 22, 2016
1 parent 7eb566a commit 0b033b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 238,8 @@

70. Retaining / removing keys is handled better when join is performed on non-key columns using `on` argument, [#1766](https://github.com/Rdatatable/data.table/issues/1766) and [#1704](https://github.com/Rdatatable/data.table/issues/1704). Thanks @mllg and @DavidArenburg.

71. `rbind` for data.tables now coerces non-list inputs to data.tables first before calling `rbindlist` so that binding list of data.tables and matrices work as expected to be consistent with base's rbind, [#1626](https://github.com/Rdatatable/data.table/issues/1626). Thanks @ems for reporting [here](http://stackoverflow.com/q/34426957/559784) on SO.

#### 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.
Expand Down
5 changes: 3 additions & 2 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2533,8 2533,9 @@ chgroup <- function(x) {
.rbind.data.table <- function(..., use.names=TRUE, fill=FALSE, idcol=NULL) {
# See FAQ 2.23
# Called from base::rbind.data.frame
l = list(...)
# if (missing(use.names)) message("Columns will be bound by name for consistency with base. You can supply unnamed lists and the columns will then be joined by position, or set use.names=FALSE. Alternatively, explicitly setting use.names to TRUE will remove this message.")
# fix for #1626.. because some packages (like psych) bind an input
# data.frame/data.table with a matrix..
l = lapply(list(...), function(x) if (is.list(x)) x else as.data.table(x))
rbindlist(l, use.names, fill, idcol)
}

Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -9093,6 9093,12 @@ res <- unique(dt[(condition1)])[unique(dt[(condition2)]),
nomatch = 0L]
test(1690.3, res[, .(points = sum(points_in_dest)), keyby = origin], data.table(origin=LETTERS[1:3], points=c(9,7,12), key="origin"))

# fix for #1626 (so that rbind plays nicely with non-list inputs, e.g., package
# psych creates a list with the input data.frame/data.table and a matrix it
# creates...)
dt = data.table(x=1:5, y=6:10)
test(1691, rbind(dt, dt), rbind(dt, as.matrix(dt)))

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

# TODO: Tests involving GForce functions needs to be run with optimisation level 1 and 2, so that both functions are tested all the time.
Expand Down
2 changes: 1 addition & 1 deletion man/data.table.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 418,7 @@ vignette("datatable-reshape")
vignette("datatable-faq")
test.data.table() # over 5300 low level tests
test.data.table() # over 5700 low level tests
# keep up to date with latest stable version on CRAN
update.packages()
Expand Down

0 comments on commit 0b033b2

Please sign in to comment.