From 50af0a2e1be488a3d5e0b52be83e698e9961156e Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 20 Jul 2020 09:46:49 +0800 Subject: [PATCH 1/2] fix eval environment for [[ GForce is.atomic test --- R/data.table.R | 6 +++--- inst/tests/tests.Rraw | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/R/data.table.R b/R/data.table.R index e95420b6e0..19b73cb038 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1539,10 +1539,10 @@ replace_dot_alias = function(e) { jvnames = sdvars } } else if (length(as.character(jsub[[1L]])) == 1L) { # Else expect problems with - # g[[ only applies to atomic input, for now, was causing #4159 + # g[[ only applies to atomic input, for now, was causing #4159. be sure to eval with enclos=parent.frame() for #4612 subopt = length(jsub) == 3L && (jsub[[1L]] == "[" || - (jsub[[1L]] == "[[" && is.name(jsub[[2L]]) && eval(call('is.atomic', jsub[[2L]]), envir = x))) && + (jsub[[1L]] == "[[" && is.name(jsub[[2L]]) && eval(call('is.atomic', jsub[[2L]]), x, parent.frame()))) && (is.numeric(jsub[[3L]]) || jsub[[3L]] == ".N") headopt = jsub[[1L]] == "head" || jsub[[1L]] == "tail" firstopt = jsub[[1L]] == "first" || jsub[[1L]] == "last" # fix for #2030 @@ -2261,7 +2261,7 @@ is.na.data.table = function (x) { Ops.data.table = function(e1, e2 = NULL) { ans = NextMethod() - if (cedta() && is.data.frame(ans)) ans = as.data.table(ans) + if (cedta() && is.data.frame(ans)) ans = as.data.table(ans) else if (is.matrix(ans)) colnames(ans) = copy(colnames(ans)) ans } diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index b990d96b29..8dd0cd5d4b 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -8088,6 +8088,13 @@ test(1581.17, DT[ , as.list(l[[f1]])[[f2]], by=c("f1","f2")], data.table(f1 = c("a", "b"), f2 = c("x", "y"), V1 = c("ax", "by"))) test(1581.18, DT[, v:=l[[f1]][f2], by=c("f1","f2")], data.table(f1=c("a","b"), f2=c("x","y"), v=c("ax", "by"))) +# When the object being [[ is in parent.frame(), not x, +# need eval to have enclos=parent.frame(), #4612 +DT = data.table(id = c(1, 1, 2), value = c("a", "b", "c")) +DT0 = copy(DT) +fun = function (DT, tag = c("A", "B")) DT[, var := tag[[.GRP]], by = "id"] +fun(DT) +test(1581.19, DT, DT0[ , var := c('A', 'A', 'B')]) # handle NULL value correctly #1429 test(1582, uniqueN(NULL), 0L) From 7fa4fd22424e52782a7d163e7316027b337ab3a1 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 20 Jul 2020 10:02:18 +0800 Subject: [PATCH 2/2] add thanks to JHY & CM in the NEWs --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3737ff26f9..80ca7dd6ed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -99,7 +99,7 @@ unit = "s") 4. If `.SD` is returned as-is during grouping, it is now unlocked for downstream usage, part of [#4159](https://github.com/Rdatatable/data.table/issues/4159). Thanks also to @mllg for detecting a problem with the initial fix here during the dev release [#4173](https://github.com/Rdatatable/data.table/issues/4173). -5. `GForce` is deactivated for `[[` on non-atomic input, part of [#4159](https://github.com/Rdatatable/data.table/issues/4159). +5. `GForce` is deactivated for `[[` on non-atomic input, part of [#4159](https://github.com/Rdatatable/data.table/issues/4159). Thanks @hongyuanjia and @ColeMiller1 for helping debug an issue in dev with the original fix before release, [#4612](https://github.com/Rdatatable/data.table/issues/4612). 6. `all.equal(DT, y)` no longer errors when `y` is not a data.table, [#4042](https://github.com/Rdatatable/data.table/issues/4042). Thanks to @d-sci for reporting and the PR.