split_terms: Split object into terms

Description Usage Arguments Details Value References See Also Examples

View source: R/split.terms.R

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)

See Also

* [terms()]

Examples

 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 )
  

formula.tools documentation built on May 2, 2019, 1:45 p.m.