check_that: Check your data

Description Usage Arguments Value Note See Also Examples

View source: R/check.R

Description

The function check_that returns FALSE if any of the predicates tested fails, TRUE otherwise.

Where check_that would return FALSE, the function ensure_that throws an error instead; otherwise it returns .data unchanged.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
check_that(.data, ...)

check_that_(.data, ..., .dots)

check(.data, ...)

ensure_that(.data, ...)

ensure_that_(.data, ..., .dots)

ensure(.data, ...)

Arguments

.data

A tbl or data.frame.

...

Logical predicates. Multiple conditions are considered as separate observations.

.dots

Used to work around non-standard evaluation.

Value

check_that returns a logical, TRUE if all checks have passed, FALSE otherwise.

ensure_that throws an error if a check fails; otherwise, .data is returned (with NULL assigned to the observations attribute).

Note

These functions are inspired by eponymous functions in package ensurer.

See Also

observe_if in this package;

check_that and ensure_that from package ensurer; check_that from package validate.

Examples

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

observe.mydata <- function(.data, ...) {
  observe_if_(.data, 
              ~ Year > 2010, 
              ~ City %in% c("Paris", "New York"), 
              ~ Population > 0)
}

df <- data.frame(City = c("Paris", "New York", "Amsterdam"), 
                 Year = c(2011, 2015, 2016), 
                 Population = c(2249975, 8550405, 840486))
class(df) <- c("mydata", "data.frame")
observe(df)
observe(df) %>% obs()
check(df)  # FALSE
## Not run: 
ensure(df) # throws an error

## End(Not run)

observer documentation built on May 1, 2019, 8:04 p.m.