Description Usage Arguments Details Value Examples
View source: R/preactionvariables.R
add_variables()
specifies the terms of the model through the usage of
tidyselect::select_helpers for the outcomes
and predictors
.
remove_variables()
removes the variables. Additionally, if the model
has already been fit, then the fit is removed.
update_variables()
first removes the variables, then replaces the
previous variables with the new ones. Any model that has already been
fit based on the original variables will need to be refit.
workflow_variables()
bundles outcomes
and predictors
into a single
variables object, which can be supplied to add_variables()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14  add_variables(x, outcomes, predictors, ..., blueprint = NULL, variables = NULL)
remove_variables(x)
update_variables(
x,
outcomes,
predictors,
...,
blueprint = NULL,
variables = NULL
)
workflow_variables(outcomes, predictors)

x 
A workflow 
outcomes, predictors 
Tidyselect expressions specifying the terms
of the model. 
... 
Not used. 
blueprint 
A hardhat blueprint used for fine tuning the preprocessing. If Note that preprocessing done here is separate from preprocessing that might be done by the underlying model. 
variables 
An alternative specification of

To fit a workflow, exactly one of add_formula()
, add_recipe()
, or
add_variables()
must be specified.
add_variables()
returns x
with a new variables preprocessor.
remove_variables()
returns x
after resetting any model fit and
removing the variables preprocessor.
update_variables()
returns x
after removing the variables preprocessor,
and then respecifying it with new variables.
workflow_variables()
returns a 'workflow_variables' object containing
both the outcomes
and predictors
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  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)
extract_mold(workflow2)$predictors
# Variables can also be added from the result of a call to
# `workflow_variables()`, which creates a standalone variables object
variables < workflow_variables(mpg, c(cyl, disp))
workflow3 < add_variables(workflow, variables = variables)
fit(workflow3, mtcars)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.