diff --git a/R/cedta.R b/R/cedta.R index 5d0a60c10..51dc0e9dd 100644 --- a/R/cedta.R +++ b/R/cedta.R @@ -22,6 +22,19 @@ cedta.pkgEvalsUserCode = c("gWidgetsWWW","statET","FastRWeb","slidify","rmarkdow # package authors could set it using assignInNamespace and then not revert its value properly which would # cause subsequent calls from other packages to fail. +# nocov start: very hard to reach this within our test suite -- the call stack within a call generated by e.g. knitr +# for loop, not any(vapply_1b(.)), to allow early exit +.any_eval_calls_in_stack <- function() { + calls = sys.calls() + # likelier to be close to the end of the call stack, right? + for (ii in length(calls):1) { # rev(seq_len(length(calls)))? See https://bugs.r-project.org/show_bug.cgi?id=18406. + the_call <- calls[[ii]][[1L]] + if (is.name(the_call) && (the_call %chin% c("eval", "evalq"))) return(TRUE) + } + return(FALSE) +} +# nocov end + # cedta = Calling Environment Data.Table-Aware cedta = function(n=2L) { # Calling Environment Data Table Aware @@ -41,7 +54,7 @@ cedta = function(n=2L) { (exists("debugger.look", parent.frame(n+1L)) || (length(sc<-sys.calls())>=8L && sc[[length(sc)-7L]] %iscall% 'example')) ) || # 'example' for #2972 (nsname=="base" && all(c("FUN", "X") %chin% ls(parent.frame(n)))) || # lapply - (nsname %chin% cedta.pkgEvalsUserCode && any(vapply_1b(sys.calls(), function(x) is.name(x[[1L]]) && (x[[1L]]=="eval" || x[[1L]]=="evalq")))) || + (nsname %chin% cedta.pkgEvalsUserCode && .any_eval_calls_in_stack()) || nsname %chin% cedta.override || isTRUE(ns$.datatable.aware) || # As of Sep 2018: RCAS, caretEnsemble, dtplyr, rstanarm, rbokeh, CEMiTool, rqdatatable, RImmPort, BPRMeth, rlist 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