R/utils-terms.R

Defines functions .multipleformula2list

.multipleformula2list <- 
function(x) {
    f <- formula(x)
    env <- environment(f)
    rval <- list()
    while(is.call(f) && f[[1L]] == "~") {
        rval[[length(rval) + 1L]] <- as.formula(f[c(1L, length(f))], env = env)
        f <- f[[2L]]
    }
    rval <- rev(rval)
    if(!identical(f, rval[[1L]][[2L]])) {
        # has lhs - attach the response to each right-sided formula:
        rval <- lapply(rval, function(g) {
            g <- g[c(1L, NA, 2L)]
            g[[2L]] <- f
            g
        })
    }
    lapply(rval, `environment<-`, env)
}

Try the MuMIn package in your browser

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

MuMIn documentation built on June 22, 2024, 6:44 p.m.