Skip to content
Prev 33540 / 63424 Next

Problem using model.frame with argument subset in own function

On Sun, 2009-08-09 at 11:32 -0500, Douglas Bates wrote:
Thanks Doug. I also received an off-list reply from Brian Ripley
suggesting two alternative approaches.

The bit I was missing was how to manipulate other aspects of the call -
it hadn't clicked that the arguments of the function can be manipulated
by altering the components of the matched call.

In the end I came up with something like:

    mf <- match.call()
    mf[[1]] <- as.name("model.frame")
    mt <- terms(formula, data = data, simplify = TRUE)
    mf[[2]] <- formula(mt, data = data)
    mf$na.action <- substitute(na.action)
    dots <- list(...)
    mf[[names(dots)]] <- NULL
    mf <- eval(mf,parent.frame())
    tran.default(mf, ...)

which seems to be working in the tests I have been running, allowing me
to pass along some components of the call to model.frame, whilst
reserving ... for the default methods arguments, and also get the
simplified formula.

All the best,

G