Description Usage Arguments Details Value Examples
Modify a formula by finding some part of it and replacing it with a new value.
1 | modify_formula(formula, find, replace, add_parens = FALSE)
|
formula |
The formula to modify (may also be a call) |
find |
A call or name (or list thereof) to search for within the formula |
replace |
A call or name (or list thereof) to replace the |
add_parens |
Add parentheses if |
Replacement occurs at the first match, so if the replacement list would modify something in the find list, that change will not occur (make two calls to the function for that effect). See the "Replacement is not sequential" examples below.
A special call can be used to expand a formula. If an expansion of arguments is desired to change a single function argument to multiple arguments, 'formulops_expand()' can be used. (See the examples.)
formula
modified
1 2 3 4 5 6 7 8 | modify_formula(a~b, find=quote(a), replace=quote(c))
modify_formula(a~b, find=quote(a), replace=quote(c+d))
modify_formula(a~b/c, find=quote(b/c), replace=quote(d))
# Replacement is not sequential
modify_formula(a~b/c, find=list(quote(b/c), quote(d)), replace=list(quote(d), quote(e)))
modify_formula(a~b/c+d, find=list(quote(b/c), quote(d)), replace=list(quote(d), quote(e)))
# Expanding arguments to functions is possible
modify_formula(a~b(c), find=quote(c), replace=quote(formulops_expand(d, e)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.