Skip to content

Commit

Permalink
Closes #833, as.data.table.list works like base R with matrices.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Mar 4, 2016
1 parent ebc0c1e commit 64f377b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions R/as.data.table.R
Expand Up @@ -95,6 +95,16 @@ as.data.table.matrix <- function(x, keep.rownames=FALSE, ...) {

as.data.table.list <- function(x, keep.rownames=FALSE, ...) {
if (!length(x)) return( null.data.table() )
# fix for #833, as.data.table.list with matrix/data.frame/data.table as a list element..
# TODO: move this entire logic (along with data.table() to C
for (i in seq_along(x)) {
dims = dim(x[[i]])
if (!is.null(dims)) {
ans = do.call("data.table", x)
setnames(ans, make.unique(names(ans)))
return(ans)
}
}
n = vapply(x, length, 0L)
mn = max(n)
x = copy(x)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -132,6 +132,8 @@

36. `fread()` handles embedded double quotes in json fields as expected, [#1164](https://github.com/Rdatatable/data.table/issues/1164). Thanks @richardtessier.

37. `as.data.table.list` handles list elements that are matrices/data.frames/data.tables properly, [#833](https://github.com/Rdatatable/data.table/issues/833). Thanks to @talexand.

#### 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
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Expand Up @@ -7487,6 +7487,12 @@ test(1610.1, capture.output(print(DT1, print.class=TRUE)),
# "2: 2016-01-02 2016-01-02 01:00:00 TRUE 2016-01-02 2",
# "3: 2016-01-03 2016-01-03 01:00:00 TRUE 2016-01-03 3"))

# fix for #833
l1 = list(a=seq_len(5), matrix(seq_len(25),ncol = 5, nrow = 5))
l2 = list(seq_len(5), matrix(seq_len(25),ncol = 5, nrow = 5))
test(1611.1, as.data.table(l1), setnames(setDT(as.data.frame(l1)), c("a", paste("V", 1:5, sep=""))))
test(1611.2, as.data.table(l2), setnames(setDT(as.data.frame(l2)), c("V1", "V1.1", paste("V", 2:5, sep=""))))

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

# 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

0 comments on commit 64f377b

Please sign in to comment.