R/stats-lm-pruning.R

#' Prune a lm object.
#'
#' Removes the environment from an lm object.
#'
#' @param x A `lm` object returned from [stats::lm()].
#'
#' @export
#' @family lm pruners
#' @seealso [stats::lm()]
prune <- function(x, ...) {
  UseMethod("prune")
}

#' @export
prune.lm <- function(x, ...){
  residue <- attributes(x$terms)
  stopifnot(is.list(residue))
  garbage <- c(".Environment",
               "dataClasses")
  for(i in garbage)
    if(i %in% names(residue)) attributes(x$terms)[i] <- NULL
  x
}
jyuu/pruneR documentation built on June 6, 2019, 12:03 a.m.