type-checkers: Type checkers

type-checkersR Documentation

Type checkers

Description

These functions make check formulae of local scope based on the correspondingly named (atomic) type predicate from base R.

Usage

vld_character(...)

vld_complex(...)

vld_double(...)

vld_integer(...)

vld_logical(...)

vld_raw(...)

Arguments

...

Check items, i.e., formulae that are one-sided or have a string as left-hand side (see Check Formulae of Local Scope in the documentation page firmly). These are the expressions to check.

Details

Each function vld_* is a function of class "check_maker", generated by localize.

Value

Check formula of local scope.

See Also

Corresponding predicates: is.character, is.complex, is.double, is.integer, is.logical, is.raw

globalize recovers the underlying check formula of global scope.

The notions of “scope” and “check item” are explained in the Check Formulae section of firmly.

Other checkers: scalar-checkers, misc-checkers

Examples

## Not run: 

f <- function(x, y) "Pass"

# Impose a check on x: ensure it's of type "logical"
f_firm <- firmly(f, vld_logical(~x))
f_firm(TRUE, 0)  # [1] "Pass"
f_firm(1, 0)     # Error: "Not logical: x"

# Use a custom error message
f_firm <- firmly(f, vld_logical("x should be a logical vector" ~ x))
f_firm(1, 0)     # Error: "x should be a logical vector"

# To impose the same check on all arguments, apply globalize()
f_firmer <- firmly(f, globalize(vld_logical))
f_firmer(TRUE, FALSE)  # [1] "Pass"
f_firmer(TRUE, 0)      # Error: "Not logical: `y`"
f_firmer(1, 0)         # Errors: "Not logical: `x`", "Not logical: `y`"

## End(Not run)

valaddin documentation built on Oct. 26, 2023, 1:07 a.m.