vadr
vadr copied to clipboard
promise extractors when no promise
arg_env gets the environment of a promise:
del <- function(x, envir=arg_env(x, environment())) {
force(envir)
.Internal(remove(x, envir, FALSE))
}
Thing is, promises are not always created with calls; the byte compiler can optimize promise creation away for literals.
library(compiler)
enableJIT(0)
f <- function() {y <- 1; del("y")}
f()
f <- cmpfun(f, options=list(optimize=1))
f() #promises creation optimized away
f <- cmpfun(f, options=list(optimize=2))
f()
# Error in arg_env(x, environment()) (from getpromise.R#39) : Expected promise, got character
- force JIT optimization to 1 on package load?
- maybe fall back on parent.frame if no other (ugh)
- one would like to still only extract the promise if is an argument, and error otherwise?
I can check JIT optimization at package load, but does that affect the compilation that is done when the package is byte-compiled?