assert {gtools}R Documentation

Generate an error if an expression is not true.

Description

Generate an error if an expression is not true.

Usage

assert(FLAG)

Arguments

FLAG Expression that should evaluate to a boolean vector

Details

Assert generate an error if its aregument does not evaluate to boolean (vector) containing only TRUE values. This is useful for defensinve programming as it provides a mechanism for checking that certain facts, the 'assertions', do in fact hold. Checking of 'assertions' is an important tool in the development of robust program code.

Value

None. Evaluated only for its side effect.

Author(s)

Gregory R. Warnes warnes@bst.rochester.edu

See Also

stop, warning

Examples


## Trivial example
posSqrt <- function(x)
  {
    assert(x>=0)
    sqrt(x)
  }

posSqrt(1:10) # works fine, no messages
## Not run: 
posSqrt(-5:5) # generates an error, since the asssertion is not met
## End(Not run)


[Package gtools version 2.4.0 Index]