formula.utils: Utilities for working with formulas

Description Usage Arguments Examples

Description

Some functions to make it easier to build and minipulate formulas

Usage

1
2
3
4
5
6
7
8
9
build_formula(lhs, rhs, env = parent.frame(), op = "+")

keep_summands(formula, n, right = TRUE, env = environment(formula),
  op = "+")

summands(formula, n, right = TRUE, op = "+")

replace_summand(formula, n, term, right = TRUE, op = "+",
  env = environment(formula))

Arguments

lhs, rhs

list or vector of character strings containing summands for left and right hand sides of a formula. NULLs are ignored.

env

an environment to attach to the formula

op

The operator to use for splitting into terms.

formula

a formula

n

a vector of integer indices. Negatives can be used to deselect.

right

a logical indicating whether to operate on the right side (else the left) of the formula.

term

a character string containing a new term

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
a <- build_formula(c("a", "b"), c("x", "y", "log(x*y)")); a
b <- build_formula("response", list("x", "y", NULL, "log(x)"), op="*"); b
f <- build_formula( "iGDP", list("iK", "iL", "iQp", "iYear")); f
g <- build_formula( "iGDP", c("iK", "iL", "iQp", "iYear")); g
identical(f,g)
summands(a)
summands(a, right=FALSE)
summands(b, op="*")
keep_summands(f, 3)
keep_summands(f, -3)
keep_summands(f, 2:4)
h <- replace_summand( f, 3, paste(summands(f, 3), lhs(f), sep="/")); h

EconModels/MacroGrowth documentation built on Dec. 17, 2019, 10:41 p.m.