# Re: [Rd] Evaluation puzzle

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 11 Nov 2010 16:07:36 -0500

On Thu, Nov 11, 2010 at 3:08 PM, Terry Therneau <therneau_at_mayo.edu> 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,
>        weights, subset, na.action, rmap,
>        times,  cohort=TRUE,  conditional=FALSE,
>        ratetable=survexp.us, scale=1, npoints, se.fit,
>        model=FALSE, x=FALSE, y=FALSE) {
>    call <- match.call()
>    m <- match.call(expand.dots=FALSE)
>
>    # keep the first element (the call), and the following selected arguments
>    m <- m[c(1, match(c('formula', 'data', 'weights', 'subset', 'na.action'),
>                      names(m), nomatch=0))]
>    m[[1]] <- as.name("model.frame")
>
>    # Add in the ratetable variables
>    varlist <- attr(ratetable, 'dimid')
>    tform <- paste(deparse(formula), paste(varlist, collapse='+'), sep='+')

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))

```--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
```
Received on Thu 11 Nov 2010 - 21:14:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 11 Nov 2010 - 22:40:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.