Test whether variables in a data frame conform to a given date format such as YYYYMMDD.

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

<tidy-select> A set of columns to test.

flt

<data-masking> A filter specifying a subset of the data frame to test.

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.

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
#> Error : `sales` has 2 records failing YYYYMM date format check on variable `quarter`.
#> Variable set: `quarter`
#> Filter: None
#> Arguments: ``
try(expect_date_yyyy(published, data = sales)) # Publication years valid
#> Error : `sales` has 4 records failing YYYY date format check on variable `published`.
#> Variable set: `published`
#> Filter: None
#> Arguments: ``