library(parsnip)
library(magrittr)
library(hardhat)
mtcars2 <- mtcars
mtcars2$gear <- frequency_weights(mtcars2$gear)
spec <- linear_reg() %>%
set_engine("lm")
wf <- workflow() %>%
add_case_weights(gear) %>%
add_formula(mpg ~ .) %>%
add_model(spec)
wf <- fit(wf, mtcars2)
# Notice that the case weights (gear) aren't included in the predictors
extract_mold(wf)$predictors
# Strip them out of the workflow, which also resets the model
remove_case_weights(wf)
Run the code above in your browser using DataLab