diff --git a/DESCRIPTION b/DESCRIPTION index 8ab2deaa0..ffa85cb31 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -64,7 +64,8 @@ Authors@R: c( person("Ben","Schwen", role="ctb"), person("Tony","Fischetti", role="ctb"), person("Ofek","Shilon", role="ctb"), - person("Vadim","Khotilovich", role="ctb")) + person("Vadim","Khotilovich", role="ctb"), + person("Hadley","Wickham", role="ctb")) Depends: R (>= 3.1.0) Imports: methods Suggests: bit64 (>= 4.0.0), bit (>= 4.0.4), curl, R.utils, xts, nanotime, zoo (>= 1.8-1), yaml, knitr, rmarkdown, markdown diff --git a/NEWS.md b/NEWS.md index 5d6a7da3e..2e0cef06a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -93,6 +93,8 @@ 13. `fifelse()` now coerces logical `NA` to other types and the `na` argument supports vectorized input, [#4277](https://github.com/Rdatatable/data.table/issues/4277) [#4286](https://github.com/Rdatatable/data.table/issues/4286) [#4287](https://github.com/Rdatatable/data.table/issues/4287). Thanks to @michaelchirico and @shrektan for reporting, and @shrektan for implementing. +14. `.datatable.aware` is now recognized in the calling environment in addition to the namespace of the calling package, [dtplyr#184](https://github.com/tidyverse/dtplyr/issues/184). Thanks to Hadley Wickham for the idea and PR. + ## BUG FIXES 1. `by=.EACHI` when `i` is keyed but `on=` different columns than `i`'s key could create an invalidly keyed result, [#4603](https://github.com/Rdatatable/data.table/issues/4603) [#4911](https://github.com/Rdatatable/data.table/issues/4911). Thanks to @myoung3 and @adamaltmejd for reporting, and @ColeMiller1 for the PR. An invalid key is where a `data.table` is marked as sorted by the key columns but the data is not sorted by those columns, leading to incorrect results from subsequent queries. diff --git a/R/cedta.R b/R/cedta.R index 7ace21007..5d0a60c10 100644 --- a/R/cedta.R +++ b/R/cedta.R @@ -18,11 +18,18 @@ cedta.pkgEvalsUserCode = c("gWidgetsWWW","statET","FastRWeb","slidify","rmarkdow # .datatable.aware = TRUE # which makes them data.table-aware optionally and possibly variably. # http://stackoverflow.com/a/13131555/403310 +# .datatable.aware is not in data.table's namespace and it is not intended to ever be added here. Otherwise +# package authors could set it using assignInNamespace and then not revert its value properly which would +# cause subsequent calls from other packages to fail. # cedta = Calling Environment Data.Table-Aware cedta = function(n=2L) { # Calling Environment Data Table Aware - ns = topenv(parent.frame(n)) + env = parent.frame(n) + if (isTRUE(env$.datatable.aware)) { # dtplyr 184 + return(TRUE) + } + ns = topenv(env) if (!isNamespace(ns)) { # e.g. DT queries at the prompt (.GlobalEnv) and knitr's eval(,envir=globalenv()) but not DF[...] inside knitr::kable v1.6 return(TRUE) @@ -47,4 +54,3 @@ cedta = function(n=2L) { } ans } -