R: Manipulate Formulae

termsinformula {spatstat.utils} | R Documentation

## Manipulate Formulae

### Description

Operations for manipulating formulae.

### Usage

    termsinformula(x)
    variablesinformula(x)
    offsetsinformula(x)
    lhs.of.formula(x)
    rhs.of.formula(x, tilde=TRUE)
    lhs.of.formula(x) <- value
    rhs.of.formula(x) <- value
    can.be.formula(x)
    identical.formulae(x,y)

### Arguments

`x,y` | Formulae, or character strings representing formulae.
`tilde` | Logical value indicating whether to retain the tilde.
`value` | Symbol or expression in the R language. See Examples.

### Details

`variablesinformula(x)` returns a character vector of the names of all variables which appear in the formula `x`.

`termsinformula(x)` returns a character vector of all terms in the formula `x` (after expansion of interaction terms).

`offsetsinformula(x)` returns a character vector of all offset terms in the formula.

`rhs.of.formula(x)` returns the right-hand side of the formula as another formula (that is, it removes the left-hand side) provided `tilde=TRUE` (the default). If `tilde=FALSE`, then the right-hand side is returned as a language object.

`lhs.of.formula(x)` returns the left-hand side of the formula as a symbol or language object, or `NULL` if the formula has no left-hand side.

`lhs.of.formula(x) <- value` and `rhs.of.formula(x) <- value` change the formula `x` by replacing the left or right hand side of the formula by `value`.

`can.be.formula(x)` returns `TRUE` if `x` is a formula or a character string that can be parsed as a formula, and returns `FALSE` otherwise.

`identical.formulae(x,y)` returns `TRUE` if `x` and `y` are identical formulae (ignoring their environments).

### Value

`variablesinformula`, `termsinformula` and `offsetsinformula` return a character vector.

`rhs.of.formula` returns a formula. `lhs.of.formula` returns a symbol or language object, or `NULL`.

`can.be.formula` and `identical.formulae` return a logical value.

### Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner r.turner@auckland.ac.nz and Ege Rubak rubak@math.aau.dk.

### Examples

      f <- (y ~ x + z*w + offset(h))
      lhs.of.formula(f)
      rhs.of.formula(f)
      variablesinformula(f)
      termsinformula(f)
      offsetsinformula(f)
      g <- f
      environment(g) <- new.env()
      identical(f,g)
      identical.formulae(f,g)
      lhs.of.formula(f) <- quote(mork) # or as.name("mork")
      f
      rhs.of.formula(f) <- quote(x+y+z) # or parse(text="x+y+z")[[1]]
      f

[Package spatstat.utils version 2.3-1 Index]