I am having a hard time understanding how quoting, unquoting, quasiquotation... works in R.
In this case I wanted to fit a linear model. I think ususally you do not need to quote the input to the lm
-call.
So I wanted to do something like this:
names(mtcars)
y = "mpg" # response
x = "hp" # predictor
fml = y ~ x
lm(fml, data=mtcars)
But obviously this does not work as literally "y" and "x" are passed int the formula. I tried several things with expr()
and eval()
but I think I am not on the right way. Reading the chapter on Metaprogramming in advanced R would certainly help a lot, but maybe there is also an "intuitive" solution here.