check_that {checkthat} | R Documentation |
Check that assertions about a dataframe are true/false
Description
This function allows you to test whether a set of assertions about a dataframe are true and to print the results of those tests. It is particularly useful for quality control and data validation.
Usage
check_that(.data, ..., print = TRUE, raise_error = TRUE, encourage = TRUE)
Arguments
.data |
A dataframe to be tested. |
... |
One or more conditions to test on the dataframe. Each condition
should be expressed as a logical expression that evaluates to a
single |
print |
Logical. If |
raise_error |
Logical. If |
encourage |
Logical. If |
Details
The check_that()
function is designed to work with both base R's
existing logical functions, as well as several new functions provided in the
checkthat package (see See Also below).
In addition, it also provides a data pronoun, .d
. This is a copy of
the .data
dataframe provided as the first argument and is useful for
testing not only features of specific rows or columns, but of the entire
dataframe, see examples.
Value
(invisibly) the original, unmodified .data
dataframe.
See Also
Examples
example_data <- data.frame(x = 1:5, y = 6:10)
# Test a dataframe for specific conditions
example_data |>
check_that(
all(x > 0),
!any(y < 5)
)
# Use .d pronoun to test aspect of entire dataframe
example_data |>
check_that(
nrow(.d) == 5,
"x" %in% names(.d)
)