formula.utilities {statnet.common}R Documentation

Functions for Querying, Validating and Extracting from Formulas A suite of utilities for handling model formulas of the style used in Statnet packages.

Description

Functions for Querying, Validating and Extracting from Formulas

A suite of utilities for handling model formulas of the style used in Statnet packages.

Usage

append_rhs.formula(
  object = NULL,
  newterms,
  keep.onesided = FALSE,
  env = environment(object)
)

append.rhs.formula(object, newterms, keep.onesided = FALSE)

filter_rhs.formula(object, f, ...)

nonsimp_update.formula(object, new, ..., from.new = FALSE)

nonsimp.update.formula(object, new, ..., from.new = FALSE)

term.list.formula(rhs, sign = +1)

list_summands.call(object)

list_rhs.formula(object)

eval_lhs.formula(object)

Arguments

object

formula object to be updated or evaluated

newterms

list of terms (names) to append to the formula, or a formula whose RHS terms will be used; either may have a "sign" attribute vector of the same length as the list, giving the sign of each term (+1 or -1).

keep.onesided

if the initial formula is one-sided, keep it whether to keep it one-sided or whether to make the initial formula the new LHS

env

an environment for the new formula, if object is NULL

f

a function whose first argument is the term and whose additional arguments are forwarded from ... that returns either TRUE or FALSE, for whether that term should be kept.

...

Additional arguments. Currently unused.

new

new formula to be used in updating

from.new

logical or character vector of variable names. controls how environment of formula gets updated.

rhs, sign

Arguments to the deprecated term.list.formula.

Value

append_rhs.formula each return an updated formula object; if object is NULL (the default), a one-sided formula containing only the terms in newterms will be returned.

nonsimp_update.formula each return an updated formula object

list_summands.call returns a list of unevaluated calls, with an additional numerical vector attribute "sign" with of the same length, giving the corresponding term's sign as +1 or -1.

list_rhs.formula returns a list of formula terms, with an additional numerical vector attribute "sign" with of the same length, giving the corresponding term's sign as +1 or -1.

eval_lhs.formula an object of whatever type the LHS evaluates to.

Functions

Examples


## append_rhs.formula

(f1 <- append_rhs.formula(y~x,list(as.name("z1"),as.name("z2"))))
(f2 <- append_rhs.formula(~y,list(as.name("z"))))
(f3 <- append_rhs.formula(~y+x,structure(list(as.name("z")),sign=-1)))
(f4 <- append_rhs.formula(~y,list(as.name("z")),TRUE))
(f5 <- append_rhs.formula(y~x,~z1-z2))
(f6 <- append_rhs.formula(NULL,list(as.name("z"))))
(f7 <- append_rhs.formula(NULL,structure(list(as.name("z")),sign=-1)))



## filter_rhs.formula
(f1 <- filter_rhs.formula(~a-b+c, `!=`, "a"))
(f2 <- filter_rhs.formula(~-a+b-c, `!=`, "a"))
(f3 <- filter_rhs.formula(~a-b+c, `!=`, "b"))
(f4 <- filter_rhs.formula(~-a+b-c, `!=`, "b"))
(f5 <- filter_rhs.formula(~a-b+c, `!=`, "c"))
(f6 <- filter_rhs.formula(~-a+b-c, `!=`, "c"))
(f7 <- filter_rhs.formula(~c-a+b-c(a),
                          function(x) (if(is.call(x)) x[[1]] else x)!="c"))




## eval_lhs.formula

(result <- eval_lhs.formula((2+2)~1))

stopifnot(identical(result,4))

[Package statnet.common version 4.5.0 Index]