Skip to content

Commit

Permalink
Closes #1341. Unlock .SD correctly for DT[i, .SD].
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Sep 26, 2015
1 parent fd826d0 commit 878bcbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,11 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
} else if ( length(jcpy <- which(sapply(jval, address) %in% sapply(SDenv, address))) ) {
for (jidx in jcpy) jval[[jidx]] = copy(jval[[jidx]])
}
} else {
if (is.data.table(jval)) {
setattr(jval, '.data.table.locked', NULL) # fix for #1341
if (!truelength(jval)) alloc.col(jval)
}
}

if (!is.null(lhs)) { # *** TO DO ***: use set() here now that it can add new column(s) and remove newnames and alloc logic above
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

6. Fixed a rare case in `melt.data.table` not setting `variable` factor column properly when `na.rm=TRUE`, [#1359](https://github.com/Rdatatable/data.table/issues/1359). Thanks @mplatzer.

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

#### 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 @@ -6987,6 +6987,12 @@ test(1562, melt(DT, measure=patterns("^g[12]"), variable.factor=FALSE), data.tab

# tet 1563 added for melt above, fix for #1359.

# fix for #1341
dt <- data.table(a = 1:10)
test(1564.1, truelength(dt[, .SD]), 100L)
test(1564.2, truelength(dt[a==5, .SD]), 100L)
test(1564.3, dt[a==5, .SD][, b := 1L], data.table(a=5L, b=1L))

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


Expand Down

0 comments on commit 878bcbc

Please sign in to comment.