type-checkers: Type checkers

Description Usage Arguments Details Value See Also Examples

Description

These functions make check formulae of local scope based on the correspondingly named type predicate from the purrr package, with the exception that vld_closure corresponds to the (inaptly named) purrr predicate is_function. For example, vld_atomic creates check formulae (of local scope) for the purrr predicate function is_atomic.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17

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: Type predicates (purrr)

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.

vld_numeric does not check according to type, and is not based on purrr::is_numeric (deprecated since 0.2.2.9000); rather, it is based on the predicate is.numeric, which checks whether an object is “numerical” in the sense of mode instead of typeof. In particular, factors are not regarded as “numerical”.

Other checkers: misc-checkers, bare-type-checkers, scalar-type-checkers

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## 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)

egnha/valaddin documentation built on Oct. 6, 2017, 3:58 p.m.