check_that | R Documentation |
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.
check_that(.data, ..., print = TRUE, raise_error = TRUE, encourage = TRUE)
.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 |
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.
(invisibly) the original, unmodified .data
dataframe.
some_of
, whenever
,
for_case
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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.