# NOT RUN {
library(parsnip)
spec_lm <- linear_reg()
spec_lm <- set_engine(spec_lm, "lm")
workflow <- workflow()
workflow <- add_model(workflow, spec_lm)
# Add terms with tidyselect expressions.
# Outcomes are specified before predictors.
workflow1 <- add_variables(
workflow,
outcomes = mpg,
predictors = c(cyl, disp)
)
workflow1 <- fit(workflow1, mtcars)
workflow1
# Removing the variables of a fit workflow will also remove the model
remove_variables(workflow1)
# Variables can also be updated
update_variables(workflow1, mpg, starts_with("d"))
# The `outcomes` are removed before the `predictors` expression
# is evaluated. This allows you to easily specify the predictors
# as "everything except the outcomes".
workflow2 <- add_variables(workflow, mpg, everything())
workflow2 <- fit(workflow2, mtcars)
pull_workflow_mold(workflow2)$predictors
# }
Run the code above in your browser using DataLab