diff --git a/R/data.table.R b/R/data.table.R index 157590e5df..d8c01f25dd 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -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 diff --git a/README.md b/README.md index a8ae661f39..d3a98d309e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index d2a1e2050f..bf5ca3c592 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -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)) + ##########################