Skip to content

Commit

Permalink
Closes #1212. dt[, get('c')] where c is a list col is handled properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Sep 26, 2015
1 parent a29390f commit 9673c89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/data.table.R
Expand Up @@ -1221,6 +1221,8 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
jval = copy(jval)
} else if ( length(jcpy <- which(sapply(jval, address) %in% sapply(SDenv, address))) ) {
for (jidx in jcpy) jval[[jidx]] = copy(jval[[jidx]])
} else if (is.call(jsub) && jsub[[1L]] == "get" && is.list(jval)) {
jval = copy(jval) # fix for #1212
}
} else {
if (is.data.table(jval)) {
Expand All @@ -1233,8 +1235,8 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
if (verbose) cat("Assigning to ",if (is.null(irows)) "all " else paste(length(irows),"row subset of "), nrow(x)," rows\n",sep="")
.Call(Cassign,x,irows,cols,newnames,jval,verbose)
return(suppPrint(x))
}
if ((is.call(jsub) && is.list(jval) && !is.object(jval)) || !missing(by)) {
}
if ((is.call(jsub) && is.list(jval) && jsub[[1L]] != "get" && !is.object(jval)) || !missing(by)) {
# is.call: selecting from a list column should return list
# is.object: for test 168 and 168.1 (S4 object result from ggplot2::qplot). Just plain list results should result in data.table

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -35,6 +35,8 @@

7. `dt[i, .SD]` unlocks `.SD` and overallocates correctly now, [#1341](https://github.com/Rdatatable/data.table/issues/1341). Thanks @marc-outins.

8. Querying a list column with `get()`, e.g., `dt[, get("c")]` is handled properly, [#1212](https://github.com/Rdatatable/data.table/issues/1212). Thanks @DavidArenburg.

#### NOTES


Expand Down
7 changes: 7 additions & 0 deletions inst/tests/tests.Rraw
Expand Up @@ -7005,6 +7005,13 @@ test(1565.2, ans1, dt[, .N, by=a])
# restore optim level
options(datatable.optimize = optim)

# Fix for #1212
set.seed(123)
dt <- data.table(a=c("abc", "def", "ghi"), b=runif(3))[, c:=list(list(data.table(d=runif(1), e=runif(1))))]
test(1566.1, dt[, c], dt[, get("c")])
test(1566.2, dt[, .(c=c)], dt[, .(c=get("c"))])
test(1566.3, address(dt$c) == address(dt[, get("c")]), FALSE)

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


Expand Down

0 comments on commit 9673c89

Please sign in to comment.