assert {gtools} | R Documentation |
Generate an error if an expression is not true.
assert(FLAG)
FLAG |
Expression that should evaluate to a boolean vector |
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.
None. Evaluated only for its side effect.
Gregory R. Warnes warnes@bst.rochester.edu
## 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)