search for: droplowmpg

Displaying 1 result from an estimated 1 matches for "droplowmpg".

2014 Feb 11
1
getting environment from "top" promise
...nvironment in which to evaluate the expression. Consider: setClass("A", representation(df = "data.frame")) setMethod("subset", "A", function(x, subset) { env <- parent.frame(2) x@df <- x@df[eval(substitute(subset), x@df, env),,drop=FALSE] x }) dropLowMpg <- function(x, cutoff=20) { invisible(subset(x, mpg > cutoff)) } a <- new("A", df=mtcars) dropLowMpg(a) The above works just fine, because we figured out that we need to evaluate in the grand-parent frame to avoid the frame of the generic call. But now let's assume A has...