toDate: Convert strings to date

Description Usage Arguments Value Examples

View source: R/dates.R

Description

toDate converts a raw date format (e.g., YY-MM-DD, MM-DD-YYYY, etc) into a normalized date format (YYYY-MM-DD) as a character vector. This is less clumsy than casting using as.character(as.Date(..., format = ....)) assuming your goal is to create the normalized character output. While not intuitive, it will also perform basic validation and is much, much quicker (through hashing, allowing multiple formats, and short-circuiting) than alternatives (inat least for my use case where I have many values, many of which are repeated)

Usage

1
toDate(chr.date.raw, lst.date.formats = NULL, log.stop.on.invalid = TRUE)

Arguments

chr.date.raw

The input date vector, as characters

lst.date.formats

Date formats, in the form of a list, with associated validation. For example, lst.date.formats = list(c(validation = '^[0-9]{2}[a-zA-Z]{3}20[0-9]{2}$', format = '%d%b%Y')) . You can include as many formats as you'd like within the lst.date.formats

log.stop.on.invalid

Should this function stop if any (non-NA) element of chr.date.raw doesn't validate across any of the validation criteria?

Value

The character vector (same ordering) in format YYYY-MM-DD

Examples

1
toDate(c('03/15/2013','03MAR2015','2015-03-12'))

sameermanek/mmisc documentation built on May 24, 2019, 7:19 a.m.