Learn R Programming

statnet.common (version 4.13.0)

term_list: A helper class for list of terms in an formula

Description

Typically generated by list_rhs.formula(), it contains, in addition to a list of call() or similar objects information about the sign of the term and the environment of the formula from which the term has been extracted, accessible and modifiable via sign() and envir() generics. Indexing and concatenation methods preserve these.

Usage

term_list(x, sign = +1L, env = NULL)

as.term_list(x, ...)

# S3 method for term_list as.term_list(x, ...)

# S3 method for default as.term_list(x, sign = +1L, env = NULL, ...)

# S3 method for term_list c(x, ...)

# S3 method for term_list [(x, i, ...)

# S3 method for term_list print(x, ...)

# S3 method for term_list sign(x)

# S3 method for term_list sign(x) <- value

# S3 method for term_list envir(object)

# S3 method for term_list envir(object) <- value

Arguments

x, object

a list of terms or a term; a term_list

sign

a vector specifying the signs associated with each term (-1 and +1)

env

a list specifying the environments, or NULL

...

additional arguments to methods

i

list index

value

RHS; see method documentation

Methods (by generic)

  • sign(term_list): An integer vector giving the signs of each term in the list.

  • sign(term_list) <- value: Update the signs of the terms; value is recycled to the length of the list.

  • envir(term_list): A list with an element for each term in the list, giving its environment.

  • envir(term_list) <- value: Update the environments of the terms; value can be an environment or a list of environments, recycled to the length of the term list.

See Also

list_rhs.formula(), list_summands.call()

Examples

Run this code

e1 <- new.env()
f1 <- a~b+c
environment(f1) <- e1
f2 <- ~-NULL+1

(l1 <- list_rhs.formula(f1))
(l2 <- list_rhs.formula(f2))

(l <- c(l1,l2))
# \dontshow{
stopifnot(identical(c(unclass(l)), alist(b, c, NULL, 1)))
stopifnot(identical(sign(l), c(1L,1L,-1L,1L)))
stopifnot(identical(envir(l), rep(list(e1, globalenv()), each=2)))
# }

(l <- c(l2[1], l1[2], l1[1], l1[1], l2[2]))
sign(l)[3] <- -1L
# \dontshow{
stopifnot(identical(c(unclass(l)), alist(NULL, c, b, b, 1)))
stopifnot(identical(sign(l), c(-1L,1L,-1L,1L,1L)))
stopifnot(identical(envir(l), list(globalenv(), e1, e1, e1, globalenv())))
# }

Run the code above in your browser using DataLab