Learn R Programming

⚠️There's a newer version (0.5.1) of this package.Take me there.

formulops

The goal of formulops is to assist with formula modification in R treating formulae as standard mathematical operations as used with nlme::nlme() and lme4::nlmer() (for treatment as statistical formula see the Formula package).

Installation

You can install the released version of formulops from CRAN with:

install.packages("formulops")

Example

A few common examples of modifying a formula are given below.

library(formulops)
# Replace a with c in the formula
modify_formula(a~b, find=quote(a), replace=quote(c))
# Replace a with c+d in the formula
modify_formula(a~b, find=quote(a), replace=quote(c+d))
# More complex parts can be replaced, too
modify_formula(a~b/c, find=quote(b/c), replace=quote(d))
# Multiple replacements can occur simultaneously
modify_formula(a~b/c+d, find=list(quote(b/c), quote(d)), replace=list(quote(d), quote(e)))
# Function arguments can be expanded
modify_formula(a~b(c), find=quote(c), replace=quote(formulops_expand(d, e)))

A substituting formula is a simple way to generate a complex formula from several simpler formulae. Parentheses are appropriately added, if required.

foo <- substituting_formula(y~x1+x2, x1~x3*x4, x2~x5/x6+x7)
as.formula(foo)

Copy Link

Version

Install

install.packages('formulops')

Monthly Downloads

163

Version

0.5.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Bill Denney

Last Published

February 22nd, 2020

Functions in formulops (0.5.0)

op_formula

Perform a mathematical operation on two formula
formula_side

Extract formula parts
formula.substituting_formula

Convert a substituting_formula object into a regular formula.
modify_formula

Modify a formula by finding some part of it and replacing it with a new value.
simplify_parens

Remove extraneous parentheses from a formula.
substituting_formula

A substituting formula helps clarify a formula where the parameters are more simply described in separate formulae.