Test whether variables in a data frame conform to a given pattern.
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.
sales <- data.frame( sale_id = 1:5, item_code = c("a_1", "b_2", "c_2", NA, "NULL") ) try(expect_regex(item_code, "[a-z]_[0-9]", data = sales)) # Codes match regex #> Error : `sales` has 1 records failing pattern check on variable `item_code`. #> Filter: None #> Arguments: `pattern = "[a-z]_[0-9]"` try(expect_max_length(item_code, 3, data = sales)) # Code width <= 3 #> Error : `sales` has 1 records failing length check on variable `item_code`. #> Filter: None #> Arguments: `len = 3`