value-expectations {testdat} | R Documentation |
Expectations: values
Description
Test whether variables in a data frame contain only certain values.
Usage
expect_values(
vars,
...,
miss = getOption("testdat.miss"),
flt = TRUE,
data = get_testdata()
)
expect_range(vars, min, max, ..., flt = TRUE, data = get_testdata())
Arguments
vars |
< |
... |
Vectors of valid values. |
miss |
A vector of values to be treated as missing. The testdat.miss or testdat.miss_text option is used by default. |
flt |
< |
data |
A data frame to test. The global test data is used by default. |
min |
Minimum value for range check. |
max |
Maximum value for range check. |
Value
expect_*()
functions are mainly called for their side effects. The
expectation signals its result (e.g. "success", "failure"), which is logged
by the current test reporter. In a non-testing
context the expectation will raise an error with class
expectation_failure
if it fails.
See Also
Other data expectations:
conditional-expectations
,
datacomp-expectations
,
date-expectations
,
exclusivity-expectations
,
expect_depends()
,
generic-expectations
,
label-expectations
,
pattern-expectations
,
proportion-expectations
,
text-expectations
,
uniqueness-expectations
Examples
sales <- data.frame(
sale_id = 1:5,
date = c("20200101", "20200101", "20200102", "20200103", "20220101"),
sale_price = c(10, 20, 30, 40, -1)
)
try(expect_values(date, 20000000:20210000, data = sales)) # Dates between 2000 and 2021
try(expect_range(sale_price, min = 0, max = Inf, data = sales)) # Prices non-negative