Skip to content

Commit 5bb6450

Browse files
Handle get0() in setDT() to preserve .internal.selfref (#7101)
* added get0 * added test and the news * tests * don't reference internal attribute * Update tests.Rraw * removed test * simplify --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 6a6147e commit 5bb6450

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ rowwiseDT(
198198
199199
20. Fixed a memory issue causing segfaults in `forder`, [#6797](https://github.com/Rdatatable/data.table/issues/6797). Thanks @dkutner for the report and @MichaelChirico for the fix.
200200
201+
21. `setDT(get0('var'))` now correctly modifies `var` by reference, consistent with the long-standing behavior of `setDT(get('var'))`, [#6864](https://github.com/Rdatatable/data.table/issues/6864). Thanks to @rikivillalba for the report and @venom1204 for the fix.
202+
201203
### NOTES
202204
203205
1. There is a new vignette on joins! See `vignette("datatable-joins")`. Thanks to Angel Feliz for authoring it! Feedback welcome. This vignette has been highly requested since 2017: [#2181](https://github.com/Rdatatable/data.table/issues/2181).

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,7 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
29822982
} else if (.is_simple_extraction(name)) {
29832983
# common case is call from 'lapply()'
29842984
.reassign_extracted_table(name, x)
2985-
} else if (name %iscall% "get") { # #6725
2985+
} else if (name %iscall% c("get", "get0")) { # #6725
29862986
# edit 'get(nm, env)' call to be 'assign(nm, x, envir=env)'
29872987
name = match.call(get, name)
29882988
name[[1L]] = quote(assign)

inst/tests/tests.Rraw

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21183,3 +21183,12 @@ test(2317.6, DT1[DF1, on='a', .(d = x.a + i.d)]$d, 5)
2118321183
test(2317.7, DT1[DF2, on='a', e := i.e]$e, 5)
2118421184
test(2317.8, DT1[DF2, on='a', e2 := x.a + i.e]$e2, 6)
2118521185
test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)
21186+
21187+
#6864
21188+
dt_get = data.frame(a = 1:3, b = letters[1:3])
21189+
setDT(get("dt_get"))
21190+
test(2319.1, !is.null(attr(dt_get, ".internal.selfref")))
21191+
21192+
dt_get0 = data.frame(a = 1:3, b = letters[1:3])
21193+
setDT(get0("dt_get0"))
21194+
test(2319.2, !is.null(attr(dt_get0, ".internal.selfref")))

0 commit comments

Comments
 (0)