You can get what you want:
model$call
And if you want to see what I found out, use:
str(model)
Since you passed the "formula" (an unsuccessful choice of names by the way) from the calling environment, which then you need to extract from the object you passed:
eval(model$call[[2]])
@JPMac offers a more compact method: formula(model) . It's also worth looking at the mechanism used by the formula.lm function. A function called formula is generic, and you use methods(formula) to find out which S3 methods are defined. Since the formula.lm method has an asterisk at the end, you need to wrap it in `getAnywhere:
> getAnywhere(formula.lm) A single object matching 'formula.lm' was found It was found in the following places registered S3 method for formula from namespace stats namespace:stats with value function (x, ...) { form <- x$formula if (!is.null(form)) { form <- formula(x$terms) environment(form) <- environment(x$formula) form } else formula(x$terms) } <bytecode: 0x36ff26158> <environment: namespace:stats>
Thus, it uses "$" to retrieve a list item named "formula" instead of pulling it out of the call. If the $ formula element is missing (which is your case), then it replaces it with formula(x$terms) , which, I suspect, calls formula.default , and looking at how this function works, only the environment correction appears object.
42-
source share