How about eval(call("lm", sformula))
?
lm(sformula)
#Call:
#lm(formula = sformula)
eval(call("lm", sformula))
#Call:
#lm(formula = "y~x")
Generally speaking there is a data
argument for lm
. Let's do:
mydata <- data.frame(y = y, x = x)
eval(call("lm", sformula, quote(mydata)))
#Call:
#lm(formula = "y~x", data = mydata)
The above call()
+ eval()
combination can be replaced by do.call()
:
do.call("lm", list(formula = sformula))
#Call:
#lm(formula = "y~x")
do.call("lm", list(formula = sformula, data = quote(mydata)))
#Call:
#lm(formula = "y~x", data = mydata)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…