Skip to content

Commit 606c4fa

Browse files
Revert "refactor cedta rules into helper"
This reverts commit 41c8f67.
1 parent 2d5d9ca commit 606c4fa

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

R/cedta.R

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,6 @@ cedta.pkgEvalsUserCode = c("gWidgetsWWW","statET","FastRWeb","slidify","rmarkdow
3939
}
4040
# nocov end
4141

42-
# in a helper to promote readability
43-
# NB: put the most common and recommended cases first for speed
44-
.cedta_impl_ <- function(ns, n) {
45-
nsname = getNamespaceName(ns)
46-
if (nsname == "data.table") return(TRUE)
47-
48-
if ("data.table" %chin% names(getNamespaceImports(ns))) return(TRUE)
49-
50-
if (nsname == "utils") {
51-
if (exists("debugger.look", parent.frame(n+1L))) return(TRUE)
52-
53-
# 'example' for #2972
54-
sc <- sys.calls()
55-
if (length(sc) >= 8L && sc[[length(sc) - 7L]] %iscall% 'example') return(TRUE)
56-
}
57-
58-
if (nsname == "base" && all(c("FUN", "X") %chin% ls(parent.frame(n)))) return(TRUE) # lapply
59-
60-
if (nsname %chin% cedta.pkgEvalsUserCode && .any_eval_calls_in_stack()) return(TRUE)
61-
62-
if (nsname %chin% cedta.override) return(TRUE)
63-
64-
# As of Sep 2018: RCAS, caretEnsemble, dtplyr, rstanarm, rbokeh, CEMiTool, rqdatatable, RImmPort, BPRMeth, rlist
65-
if (isTRUE(ns$.datatable.aware)) return(TRUE)
66-
67-
# both ns$.Depends and get(.Depends,ns) are not sufficient
68-
pkg_ns = paste("package", nsname, sep=":")
69-
tryCatch("data.table" %chin% get(".Depends", pkg_ns, inherits=FALSE), error=function(e) FALSE)
70-
}
71-
7242
# cedta = Calling Environment Data.Table-Aware
7343
cedta = function(n=2L) {
7444
# Calling Environment Data Table Aware
@@ -81,10 +51,20 @@ cedta = function(n=2L) {
8151
# e.g. DT queries at the prompt (.GlobalEnv) and knitr's eval(,envir=globalenv()) but not DF[...] inside knitr::kable v1.6
8252
return(TRUE)
8353
}
84-
ans = .cedta_impl_(ns, n)
54+
nsname = getNamespaceName(ns)
55+
ans = nsname=="data.table" ||
56+
"data.table" %chin% names(getNamespaceImports(ns)) || # most common and recommended cases first for speed
57+
(nsname=="utils" &&
58+
(exists("debugger.look", parent.frame(n+1L)) ||
59+
(length(sc<-sys.calls())>=8L && sc[[length(sc)-7L]] %iscall% 'example')) ) || # 'example' for #2972
60+
(nsname=="base" && all(c("FUN", "X") %chin% ls(parent.frame(n)))) || # lapply
61+
(nsname %chin% cedta.pkgEvalsUserCode && .any_eval_calls_in_stack()) ||
62+
nsname %chin% cedta.override ||
63+
isTRUE(ns$.datatable.aware) || # As of Sep 2018: RCAS, caretEnsemble, dtplyr, rstanarm, rbokeh, CEMiTool, rqdatatable, RImmPort, BPRMeth, rlist
64+
tryCatch("data.table" %chin% get(".Depends",paste("package",nsname,sep=":"),inherits=FALSE),error=function(e)FALSE) # both ns$.Depends and get(.Depends,ns) are not sufficient
8565
if (!ans && getOption("datatable.verbose")) {
8666
# nocov start
87-
catf("cedta decided '%s' wasn't data.table aware. Here is call stack with [[1L]] applied:\n", getNamespaceName(ns))
67+
catf("cedta decided '%s' wasn't data.table aware. Here is call stack with [[1L]] applied:\n", nsname)
8868
print(sapply(sys.calls(), `[[`, 1L))
8969
# nocov end
9070
# so we can trace the namespace name that may need to be added (very unusually)

0 commit comments

Comments
 (0)