Displaying 1 result from an estimated 1 matches for "top_prenv".
Did you mean:
top_env
2014 Feb 11
1
getting environment from "top" promise
...ot;subset", "B", function(x, ...) {
ans <- callNextMethod()
ans@nrow <- nrow(ans@df)
ans
})
b <- new("B", df=mtcars)
dropLowMpg(b)
Error in eval(expr, envir, enclos) (from #3) : object 'cutoff' not found
We can fix this with a simple C function:
SEXP top_prenv(SEXP nm, SEXP env)
{
SEXP promise = findVar(nm, env);
while(TYPEOF(promise) == PROMSXP) {
env = PRENV(promise);
promise = PREXPR(promise);
}
return env;
}
With R wrapper:
top_prenv <- function(x) {
.Call2("top_prenv", substitute(x), parent.frame())
}
Then this works...