From these strings
data = "mtcars" y = "mpg" x = c("cyl","disp")
, I am trying to perform a linear model. I tried things like
epp=function(x) eval(parse(text=paste0(x,collapse="+"))) lm(data=epp(data),epp(y)~epp(x)) # Error in eval(expr, envir, enclos) : object 'cyl' not found
where the last line was aimed to be equivalent to
This involves two operations that are both described in multiple SO entries that use perhaps singly either the
lm(data=get(data), formula=as.formula( paste( y, "~", paste(x, collapse="+") ) ) )
In both cases you are use a text/character object to return a language object. In the first argument
get returns a 'symbol' that can be evaluated and in the second instance
as.formula returns a 'formula' object. @blmoore is correct in advising us that
lm will accept a character object, so the as.formula call is not needed here.
lmdo the coercion to formula from character
eval(parse(...because it usually a method to cast R in a macro-processing mode of programming. To
blmoore: I didn't realize that NSE had descended into
lmprocessing of character values, but I guess it doesn't really create any ambiguity.