split_terms: Split object into terms In formula.tools: Programmatic Utilities for Manipulating Formulas, Expressions, Calls, Assignments and Other R Objects

Description

Split formulas, call and expressions into terms.

Usage

 `1` ```split_terms(x, recursive = FALSE) ```

Arguments

 `x` object to split terms from `recursive` logical; whether to split terms recursively in parenthetical enclosed terms (depth-first). (Default: FALSE)

Details

Unlike the [terms()] function, 'split_terms' does not use [stats::terms()] and instead just splits 'x' into an **expression vector** of terms. (Terms are the mathematical notion of terms). The signs of the terms are preserved.

If 'recursive' is 'TRUE', splitting occurs recursively, i.e. parsing of the input descends into parenthetical expressions '(...)'.

See **examples**.

Value

experession vector of terms

References

* [SO: How to split a formula](https://stackoverflow.com/questions/39155701/how-to-split-a-formula-in-r)

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23``` ``` split_terms(1) # 1 split_terms( quote(a) ) # a split_terms( quote(-a) ) # -a split_terms( quote(a+1) ) # a, 1 split_terms( quote(1+a) ) # 1, a split_terms( quote(-1+a) ) # -1, a split_terms( quote(-1-a) ) split_terms( quote(a+b+c) ) # a,b,c split_terms( quote((a+b)+1) ) # (a+b),1 split_terms( quote((a+b)+1), recursive=TRUE ) # a,b,1 split_terms( quote((a-b)+1), recursive=TRUE ) # a,-b,1 split_terms( quote(-a) ) # -a split_terms( quote(a-1) ) # a, -1 split_terms( quote(-a-1)) # -a, -1 split_terms( quote( -(a+1) ) ) # -(a+1) split_terms( quote( -(a+1) ), recursive=TRUE ) # -a,-1 split_terms( quote( ---a )) split_terms( quote( -(a+(b-(c+d)))), recursive=TRUE ) ```