Skip to content

model.frame and parent environment

1 message · Terry Therneau

#
Duncan,
   You missed the point.  (I sometimes write too tersely, so I take the blame.)  Users are 
writing their own "myfun".  I want model.frame to work for them, without forcing the user 
to learn environment trickery.   The actual question from the user was a call to
        fit <- coxph(formula, data=nd)
        predict(fit, type='expected')
Within the predict call it is model.frame that fails, in the same way that it does in my 
simplified example.

Now within model.frame.coxph (and model.frame.lm) there is the line
       eval(fexpr, env, parent.frame())
where env = environment of the formula and fexpr is an unevaluated call to model.frame. 
My underneath question: why is the enclosure argment ignored in this particular case? 
Parent.frame includes "nd".

I have to admit that I find the non-functional parts of scheme, which R inherited, 
continue to leave me with the emotional response of "why would you add such nastiness to a 
language"?   This leaves me at a disadvantage, I suspect, when trying to trace these 
things out.  I've not yet seen a situation where I would want a formula to reference 
non-local information.

Aside: The horrible decision in S to have "data=" replace rather than augment the scope 
for variable matching caused a lot of grief when calling a model inside a function.  The R 
paradym fixed that, for which I am grateful, but with serious consequences.

Terry T.
On 06/16/2014 06:26 PM, Duncan Murdoch wrote: