axe-lm {butcher} | R Documentation |
Axing an lm.
Description
lm objects are created from the base stats package.
Usage
## S3 method for class 'lm'
axe_call(x, verbose = FALSE, ...)
## S3 method for class 'lm'
axe_env(x, verbose = FALSE, ...)
## S3 method for class 'lm'
axe_fitted(x, verbose = FALSE, ...)
Arguments
x |
A model object. |
verbose |
Print information each time an axe method is executed.
Notes how much memory is released and what functions are
disabled. Default is |
... |
Any additional arguments related to axing. |
Value
Axed lm object.
Examples
# Load libraries
library(parsnip)
library(rsample)
# Load data
split <- initial_split(mtcars, prop = 9/10)
car_train <- training(split)
# Create model and fit
lm_fit <- linear_reg() %>%
set_engine("lm") %>%
fit(mpg ~ ., data = car_train)
out <- butcher(lm_fit, verbose = TRUE)
# Another lm object
wrapped_lm <- function() {
some_junk_in_environment <- runif(1e6)
fit <- lm(mpg ~ ., data = mtcars)
return(fit)
}
# Remove junk
cleaned_lm <- axe_env(wrapped_lm(), verbose = TRUE)
# Check size
lobstr::obj_size(cleaned_lm)
# Compare environment in terms component
lobstr::obj_size(attr(wrapped_lm()$terms, ".Environment"))
lobstr::obj_size(attr(cleaned_lm$terms, ".Environment"))
[Package butcher version 0.3.4 Index]