[Rd] Evaluation puzzle
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Nov 11 22:07:36 CET 2010
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
More information about the R-devel
mailing list