R/as.operator.R

Defines functions as.operator as.operator.function as.operator.character as.operator.name

# ---------------------------------------------------------------------
# as.operator:
#   coerce to an operator
#   similar to 'as.function', but will only work for operators.
# ---------------------------------------------------------------------

as.operator <- function(x, ...) {
  UseMethod( 'as.operator', x ) 
}

as.operator.function <- function(x, ...)
  if( is.operator(x) ) return(x) else
    stop( x, " cannot be coerced to an operator." )


as.operator.character <- function(x, ...)
  if( x %in% operators(...) ) eval( as.name(x) ) else
    stop( x, " cannot be coerced to an operator." )


as.operator.name <- function(x, ... ) 
  if( deparse(x) %in% operators(...) ) eval( x ) else
    stop( x, " cannot be coerced to an operator." )  

Try the operator.tools package in your browser

Any scripts or data that you put into this service are public.

operator.tools documentation built on May 1, 2019, 8 p.m.