R/model.frame.rpart.R

Defines functions model.frame.rpart

model.frame.rpart <- function(formula, ...)
{
    m <- formula$model
    if (!is.null(m)) return(m)
    oc <- formula$call
    if (substring(deparse(oc[[1L]]), 1L, 7L) == "predict") {
        m <- eval(oc$newdata)
        if (is.null(attr(m, "terms"))) {
            object <- eval(oc$object)
            m <- model.frame(object$terms, m, na.rpart)
        }
        return(m)
    }
    while(!deparse(oc[[1L]]) %in%  c("rpart", "rpart::rpart", "rpart:::rpart"))
        oc <- eval(oc[[2L]])$call
    oc$subset <- names(formula$where)
    oc$method <- formula$method
    eval(oc)
}

Try the rpart package in your browser

Any scripts or data that you put into this service are public.

rpart documentation built on Oct. 10, 2023, 1:08 a.m.