Skip to content

Commit d263924

Browse files
Allow setDT(get(...)) to work as previously (#6726)
* Allow setDT(get(...)) to work as previously * Quirks of test.data.table... * need to eval() in the right place * imitate the approach in other branches more closely * maybe we just needed enclos=? * Comment for posterity * Actually do the test
1 parent 1dd2976 commit d263924

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

R/data.table.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,6 +2987,12 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
29872987
} else if (isS4(k)) {
29882988
.Call(CsetS4elt, k, as.character(name[[3L]]), x)
29892989
}
2990+
} else if (name %iscall% "get") { # #6725
2991+
# edit 'get(nm, env)' call to be 'assign(nm, x, envir=env)'
2992+
name = match.call(get, name)
2993+
name[[1L]] = quote(assign)
2994+
name$value = x
2995+
eval(name, parent.frame(), parent.frame())
29902996
}
29912997
.Call(CexpandAltRep, x) # issue#2866 and PR#2882
29922998
invisible(x)

inst/tests/tests.Rraw

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20653,6 +20653,18 @@ setDT(d2)
2065320653
test(2295.1, !is.data.table(d1))
2065420654
test(2295.2, rownames(d1), 'b')
2065520655
test(2295.3, is.data.table(d2))
20656+
# Ensure against regression noted in #6725
20657+
x = data.frame(a=1)
20658+
e = environment()
20659+
foo = function(nm, env) {
20660+
setDT(get(nm, envir=env))
20661+
}
20662+
foo('x', e)
20663+
test(2295.4, is.data.table(x))
20664+
e = new.env(parent=topenv())
20665+
e$x = data.frame(a=1)
20666+
foo('x', e)
20667+
test(2295.5, is.data.table(e$x))
2065620668

2065720669
# #6588: .checkTypos used to give arbitrary strings to stopf as the first argument
2065820670
test(2296, d2[x %no such operator% 1], error = '%no such operator%')

0 commit comments

Comments
 (0)