validate: Validate objects

Description Usage Arguments Examples

View source: R/validate.R

Description

Validate objects

Usage

1
2
3
validate(., ..., .checklist = list(), .error_class = "validationError")

.f %checkout% .checks

Arguments

.

Object to validate.

...

Input-validation check formula(e).

.checklist

List of check formulae. (These are combined with check formulae provided via ....)

.error_class

Subclass of the error condition to be raised when an input validation error occurs (character).

.f

Interpreted function, i.e., closure.

.checks

List of check formulae, optionally containing a character vector named .error_class, corresponding to the similarly named argument.

Examples

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

# Valid assertions: data frame returned (invisibly)
mtcars %>%
  validate(
    vld_all(~sapply(., is.numeric)),
    ~{nrow(.) > 10},
    vld_all(~c("mpg", "cyl") %in% names(.))
  )

# Invalid assertions: error raised
mtcars %>%
  validate(
    vld_all(~sapply(., is.numeric)),
    ~{nrow(.) > 1000},
    vld_all(~c("mpg", "cylinders") %in% names(.))
  )

## End(Not run)

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