check_that {observer} | R Documentation |
Check your data
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
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
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)