makeChecks: Automatic Generation of Validaton Functions

Description Usage Arguments Details Examples

Description

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.

Usage

1
2
makeChecks(assertionName, cond, errormsg, args = alist(x=),
  pos = -1)

Arguments

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.

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.

Examples

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

RaphaelS1/RSmisc documentation built on June 7, 2019, 8:20 p.m.