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

lhs(x, ...)

# S4 method for class 'call'
lhs(x)

# S4 method for class 'formula'
lhs(x)



# S4 method for class 'expression'
lhs(x, ...)

# S4 method for class 'list'
lhs(x, ...)

lhs(x) <- value

# S4 method for class 'call'
lhs(x) <- value

# S4 method for class 'formula'
lhs(x) <- value



.replace.lhs.plural(x, value)

# S4 method for class 'expression'
lhs(x) <- value

# S4 method for class 'list'
lhs(x) <- value

op(x)

# S4 method for class 'formula'
op(x)

# S4 method for class 'call'
op(x)

# S4 method for class 'name'
op(x)

# S4 method for class 'expression'
op(x)

# S4 method for class 'list'
op(x)



op(x) <- value

# S4 method for class 'call'
op(x) <- value

# S4 method for class 'formula'
op(x) <- value



.replace.op.plural(x, value)

# S4 method for class 'expression'
op(x) <- value

# S4 method for class 'list'
op(x) <- value

rhs(x, ...)

.rhs.singular(x)

# S4 method for class 'call'
rhs(x)

# S4 method for class 'formula'
rhs(x)



# S4 method for class 'expression'
rhs(x, ...)

# S4 method for class 'list'
rhs(x, ...)

rhs(x) <- value

.replace.rhs.singular(x, value)

# S4 method for class 'call'
rhs(x) <- value

# S4 method for class 'formula'
rhs(x) <- value



.replace.rhs.plural(x, value)

# S4 method for class 'expression'
rhs(x) <- value

# S4 method for class 'list'
rhs(x) <- value

Arguments

x

object from where to get/set the lhs/rhs

...

arguments passed to additional methods

value

the value to set for the lhs/rhs

Value

Value depends on the argument.

Details

lhs retrieves the left-hand side rhs retrieves the right-hand side op retrieves the operation op.type returns the type operator

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.

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 operator types are defined by the operator.tools package: See operators and setOperator

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.

Note

Methods for the non-standard "<-" class exist and are not included in the usage documentation because CRAN does not support S4 documentation for this class.

See also

terms, all.vars, all.names, operators

Author

Christopher Brown

Examples


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

  rhs(f)
#> C + D
  rhs(f) <- quote( G + H ) 
  op(f)
#> `~`
  op(rhs(f))
#> `+`
  op( quote(A) )  # NULL: 
  op.type(f)
#> [1] "tilde"

  # ONE-SIDED FORMULA
  f <- ~ A   # 
  lhs(f)     # NULL
#> NULL
  rhs(f)     # A
#> A


  # EXPRESSION
  e <- expression( A + B == C + D )
  lhs(e)
#> expression(A + B)
  rhs(e)
#> expression(C + D)
  op(e)
#> expression(`==`)
  op.type(e)
#> [[1]]
#> [1] "relational"
#> 


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

  op(c)
#> `>`
  op.type(c)
#> [1] "relational"

  # ASSIGNMENT 
  a  <- quote( A <- B ) 
  lhs(a)
#> A
  rhs(a) 
#> B
  op(a)
#> `<-`
  op.type(a) 
#> [1] "assignment"