formula.terms-methods {formula.tools}R Documentation

Manipulate the component parts of formulas, expressions, calls, name/symbols and many values objects of these such as list and vectors.

Description

lhs, rhs, op, and op.type retrieve the various parts of R formulas, expressions, calls and names/symbols. These functions were designed to greatly facilitate symbolic manupulation using native R objects. Also provided are methods to handle lists of these objects.

lhs retrieves the left-hand side
rhs retrieves the right-hand side
op retrieves the operation
op.type returns the type of logical operation, one of: 'gt', 'lt', 'eq', 'ne' or '~'

There are also functions lhs.vars and rhs.vars. Like all.vars , these functions interpret the variables on the left-hand and right-hand sides respectively.

Usage

 

  lhs(x, ...)
  rhs(x, ...)
  op(x, ...)
  op.type(x, ...) 

  lhs.vars( x, ... )
  rhs.vars( x, ... )

Arguments

x A formula, expression, call or name/symbols
... Arguments passed to succeeding functions

Details

These are simple functions for extracting the left-hand side, right-hand side, operator and operator type from formulas, expressions, calls, names/symbols and list containing these objects.

lhs, rhs are only defined for formulas and calls ( and list and expressions ) that are defined with either one of the relational or tilde ('~') operators. If the object does not contain one of these operators, it will fail with a warning.

The defined op.types are 'gt', 'lt', 'eq', 'ne' and '~'.

The lhs.vars and rhs.vars methods, return the variables used on the lhs and rhs, respectively. If special formula variables are used, such as '.', a data.frame or environment must also be provided such that the variable list may be properly infered.

Value

Value depends on the argument.

Methods

x = "call"
For call objects
x = "expression"
For expression objects
x = "formula"
For formula objects
x = "list"
For list objects

Author(s)

Christopher Brown

See Also

terms, all.vars, all.names, relational.operators

Examples


  # FORMULA
  f <- A + B ~ C + D
  lhs(f)
  lhs(f) <- quote( E / F )

  rhs(f)
  rhs(f) <- quote( G + H ) 
  op(f)
  op.type(f)

  # EXPRESSION
  e <- expression( A + B == C + D )
  lhs(e)
  rhs(e)
  op(e)
  op.type(e)

  # CALL
  c <- quote( A + B > C + D )
  lhs(c)
  lhs(c) <- quote(E)
  rhs(c)

  op(c)
  op.type(c)


[Package formula.tools version 0.14.1 Index]