You can do some simple language calculations using bquote to build your challenge.
temp_fm_list = lapply(temp_formula_list, function(x) { lmc <- bquote( lm(data = mtcars, formula = .(x))) eval(lmc) }) temp_fm_list # Call: # lm(formula = hp ~ 1, data = mtcars) # # Coefficients: # (Intercept) # 146.7 # # # [[2]] # # Call: # lm(formula = hp ~ cyl, data = mtcars) # # Coefficients: # (Intercept) cyl # -51.05 31.96
note that
function(x) do.call('lm', list(formula = x, data = quote(mtcars))
Will also work
Other approaches ....
Even with your initial call, you can recreate the formula from the terms object associated with the model
eg,
x <- hp ~ cyl lmo <- lm(formula = x, data = mtcars) formula(lmo)
You can use this call object if you want (although this is a pretty dangerous practice)
# for example lmo$call$formula <- x lmo$call
source share