validate
validate copied to clipboard
Add convenience function to check if a field can be interpreted as date.
e.g. YYYYMMDD (as integer) or ISO8601 formats.
I'm also interested in this!
Unfortunately I'm unaware of any simple, readable way to implement this in R.
A function like this might be suitable?
date_format <- function(x) {
return(
# YYYY-MM-DD
# https://en.wikipedia.org/wiki/ISO_8601#Dates
# YYYY = Four digits
# MM = a zero-padded number 01-12
# DD = a zero padded number 00-31
grepl("^\\d{4}-([0]\\d|1[0-2])-([0-2]\\d|3[01])$", x)
)
}