Modify components of a formula by adding / removing vars from the rhs or replacing the lhs.
f_modify_formula(
f,
rhs_remove = NULL,
rhs_add = NULL,
lhs_replace = NULL,
negate = TRUE
)
formula
regex or character vector for dropping variables from the rhs
character vector for adding variables to rhs
string to replace formula lhs if supplied
should rhs_remove
keep or remove the specified vars. Set to FALSE
to keep
formula
iris %>%
tidy_formula(target = Species, tidyselect::everything()) -> f
f
#> Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
#> <environment: 0x134e47940>
f %>%
f_modify_formula(
rhs_remove = c("Petal.Width", "Sepal.Length"),
rhs_add = "Custom_Variable"
)
#> Species ~ Sepal.Width + Petal.Length + Custom_Variable
#> <environment: 0x135014548>
f %>%
f_modify_formula(
rhs_remove = "Petal",
lhs_replace = "Petal.Length"
)
#> Petal.Length ~ Sepal.Length + Sepal.Width
#> <environment: 0x1350a3000>