date-expectations {testdat} | R Documentation |
Expectations: dates
Description
Test whether variables in a data frame conform to a given date format such as YYYYMMDD.
Usage
expect_date_yyyy(vars, flt = TRUE, data = get_testdata())
expect_date_yyyymm(vars, flt = TRUE, data = get_testdata())
expect_date_yyyymmdd(vars, flt = TRUE, data = get_testdata())
Arguments
vars |
< |
flt |
< |
data |
A data frame to test. The global test data is used by default. |
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
,
exclusivity-expectations
,
expect_depends()
,
generic-expectations
,
label-expectations
,
pattern-expectations
,
proportion-expectations
,
text-expectations
,
uniqueness-expectations
,
value-expectations
Examples
sales <- data.frame(
sale_id = 1:5,
date = c("20200101", "20200101", "20200102", "20200103", "20220101"),
quarter = c(202006, 202009, 202012, 20203, 20200101),
published = c(1999, 19991, 21, 0001, 20200101)
)
try(expect_date_yyyymmdd(date, data = sales)) # Full date of sale valid
try(expect_date_yyyymm(quarter, data = sales)) # Quarters given as YYYYMM
try(expect_date_yyyy(published, data = sales)) # Publication years valid