bare-type-checkers: Bare type checkers

Description Usage Arguments Details Value See Also Examples

Description

These functions make check formulae of local scope based on the correspondingly named bare type predicate from the purrr package. For example, vld_bare_atomic creates check formulae (of local scope) for the purrr predicate function is_bare_atomic.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

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: Bare 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.

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 

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

# Impose a check on x: ensure it's a bare logical object (i.e., has no class)
f_firm <- firmly(f, vld_bare_logical(~x))
x <- structure(TRUE, class = "boolean")
f_firm(TRUE, 0)  # [1] "Pass"
f_firm(x, 0)     # Error: "Not bare logical: x"

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

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

## End(Not run)

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