predicates: Basic predicates for validation

Description Examples

Description

The following predicate functions augment predicates from the base and rlang packages to enable them to produce informative error messages when used as checks in fasten(), firmly(), validator(), validate().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## chk_double() and rlang::is_double() are identical as functions
chk_double(runif(2))
chk_double(runif(2), n = 1)
chk_double(1:2)
rlang::is_double(runif(2))
rlang::is_double(runif(2), n = 1)
rlang::is_double(1:2)

## But when rlang::is_double() is used in firmly(),
## it produces an auto-generated error message ...
## Not run: 
firmly(function(x) x, rlang::is_double(n = 1))(runif(2))
## End(Not run)

## ... whereas chk_double() produces a specialized error message
## Not run: 
firmly(function(x) x, chk_double(n = 1))(runif(2))
## End(Not run)

## Not run: 
validate(mtcars, is.matrix, {"cylinder" %in% names(.)})
validate(mtcars, chk_matrix, chk_has_name("cylinder"))
## End(Not run)

egnha/rong documentation built on May 7, 2019, 9:48 p.m.