Re: [Rd] Evaluation puzzle

2010-11-11 Thread Peter Dalgaard
On 11/11/2010 11:27 PM, Terry Therneau wrote: > I'm still puzzled by recover though. It looks like a buglet. You get to the right frame (try ls()) but the "called from" message is off by four frames. E.g. Selection: 1 Called from: model.frame(formula = "zed ~ 1+age+sex+year", data = mydata) Br

Re: [Rd] Evaluation puzzle

2010-11-11 Thread Terry Therneau
Kevin, The answer came from Gabor -- the model.frame function has a non-standard evaluation, in that it uses the enviromnent attached to the formula as the "enclosure" for looking up variable names. This is clearly documented and I somehow missed it when reading the page. So "reading deficit"

Re: [Rd] Evaluation puzzle

2010-11-11 Thread Gabor Grothendieck
On Thu, Nov 11, 2010 at 5:27 PM, Terry Therneau wrote: > Gabor wrote: >  At the above statement you have lost the environment of your formula. > >>    m$formula <- tform > > Replace this with: > > m$formula <- as.formula(tform, environment(formula)) > > -- >  No, I have not "lo

Re: [Rd] Evaluation puzzle

2010-11-11 Thread Kevin R. Coombes
Hi Terry, This may not really be a complete answer, but there seems to be a difference in eval'ing an expression compared to eval'ing a call (even though both are documented in the help page for eval as working just fine). If you insert the line print(eval(expression(zed), parent.frame())

Re: [Rd] Evaluation puzzle

2010-11-11 Thread Terry Therneau
Gabor wrote: At the above statement you have lost the environment of your formula. >m$formula <- tform Replace this with: m$formula <- as.formula(tform, environment(formula)) -- No, I have not "lost" an environment. I manufactured a formula which lacked something ne

Re: [Rd] Evaluation puzzle

2010-11-11 Thread Gabor Grothendieck
On Thu, Nov 11, 2010 at 3:08 PM, Terry Therneau wrote: > The survexp function can fail when called from another function.  The "why" of > this has me baffled, however. > > Here is a simple test case, using a very stripped down version of survexp: > > survexp.test <- function(formula, data, >      

[Rd] Evaluation puzzle

2010-11-11 Thread Terry Therneau
The survexp function can fail when called from another function. The "why" of this has me baffled, however. Here is a simple test case, using a very stripped down version of survexp: survexp.test <- function(formula, data, weights, subset, na.action, rmap, times, cohort=TRUE,