Description Usage Arguments Details Examples
This function uses the generalised assertion functions to assign assert/check/test/is functions to the given environment for quick deployment of validation checks. See examples for how it is used in distr6.
1 2 | makeChecks(assertionName, cond, errormsg, args = alist(x=),
pos = -1)
|
assertionName |
name that follows assert/check/test/is |
cond |
Boolean condition to check |
errormsg |
Error message to produce |
args |
Generic argument names for object to validate. See Details. |
pos |
Environment position to assign functions to. See Details. |
This generates simplified version of more complex assertion and validation
functions that can be found in libraries such as checkmate
. The purpose
of which is to easily define validation checks that are used throughout distr6.
By default, validations are only made in relation to one argument however this can be
extended by adding arguments to the args
parameter. For example, args = alist(x=, y=,...)
.
Validation functions are assigned to the current parent environment, which is often .GlobalEnv
however when loading and attaching libraries, it is the current library being loaded.
1 2 3 4 5 6 7 | makeChecks(assertionName = "Numeric",
cond = inherits(x,"numeric"),
errormsg = paste(x,"is not numeric"), pos = 1)
assertNumeric(as.numeric(0)) # silent
checkNumeric(as.numeric(1)) # TRUE
testNumeric("a") # FALSE
isNumeric("2") # FALSE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.