R/attributes.R

Defines functions prune_attributes add_attributes

add_attributes <- function(out, mfx = NULL, ...) {
    # Always add all attributes from S4 slots
    if (!is.null(mfx)) attr(out, "marginaleffects") <- mfx

    dots <- list(...)
    for (n in names(dots)) {
        if (is.null(attr(out, n))) {
            attr(out, n) <- dots[[n]]
        }
    }

    return(out)
}


prune_attributes <- function(out) {
    if (isTRUE(getOption("marginaleffects_lean", default = FALSE))) {
        out <- prune(out, component = "all")
    } else {
        out <- prune(out, component = "modeldata")
    }
    return(out)
}

Try the marginaleffects package in your browser

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

marginaleffects documentation built on Sept. 13, 2025, 5:07 p.m.