formula.tools

** Utilities for Formulas, Expressions, Calls, Assignments and Other R Objects**

CRAN_Status_Badge License Downloads software impact

These utilities facilitate the programmatic manipulations of formulas, expressions, calls, names, symbols and other R language objects. These objects all share the same structure: a left-hand side (lhs), an operator (op) and right-hand side (rhs). This packages provides methods for accessing and modifying this structures as well as extracting and replacing names and symbols from these objects.

It is easiest to understand through the [#Examples].

Installation

Stable Version

install.packages('formula.tools')

Development Verison

devtools::install_github("decisionpatterns/formula.tools")

Overview

Manipulate parts of a formula/expression/call/assignment:

Get variables (names) in a formula/expression/call/assignment:

Get terms from formula or expression:

Examples

Formula terms and operators can be accessed or changed.


## Get parts of formula 

form <- y ~ x 

lhs(form)                # y
lhs(form) <- quote(t)
form                     # t ~ x

rhs(form)                # x
rhs(form) <- 1
form                     # t ~ 1


## Get variables (names)

form <- y ~ m*x + b

get.vars(form)           # "y" "m" "x" "b"
lhs.vars(form)           # "y"
rhs.vars(form)           # "m" "x" "b"


## Split terms

terms(form)

split_terms(form)        # expression(Species ~ . - Sepal.Length)
split_terms( quote(a+(b+(c+d))), recursive=TRUE )   # expression(a, b, c, d)

mirror server hosted at Truenetwork, Russian Federation.