R: Evaluate an expression in a data frame with arguments that are passed as an object
问题 I want to write a function that evaluates an expression in a data frame, but one that does so using expressions that may or may not contain user-defined objects. I think the magic word is "non-standard evaluation", but I cannot quite figure it out just yet. One simple example (yet realistic for my purposes): Say, I want to evaluate an lm() call for variables found in a data frame. mydf <- data.frame(x=1:10, y=1:10) A function that does so can be written as follows: f <- function(df, expr){