likedate {easyr}R Documentation

Like Date

Description

Check if a column can be converted to a date. Helpful for checking a column before actually converting it. Author: Bryce Chamberlain. Tech review: Dominic Dillingham.

Usage

likedate(
  x,
  na_strings = easyr::nastrings,
  run_unique = TRUE,
  aggressive.extraction = TRUE
)

Arguments

x

Value or vector to check.

na_strings

Vector of characters to consider NA. Like Date will treat these values like NA.

run_unique

Convert to unique variables before checking. In some cases, this can make it take longer than necessary. In most, it will make it faster.

aggressive.extraction

todate will take dates inside long strings (like filenames) and convert them to dates. This seems to be the preferred outcome, so we leave it as default (TRUE). However, if you want to avoid this you can do so via this option (FALSE).

Value

Boolean indicating if the entire vector can be converted to a date.

Examples

x <- c('20171124','2017/12/24',NA,'12/24/2017','March 3rd, 2015','Mar 3, 2016')
likedate(x)
likedate(c(123,456,NA))
if(likedate(x)) t <- todate(x)
likedate(lubridate::mdy('1-1-2014'))
likedate( '3312019' )
likedate( '2019.1.3' )

[Package easyr version 0.5-8 Index]