to_ISO_8601: Coerce character strings to the Date class

Description Usage Arguments Value Author(s) See Also Examples

Description

Coerce character strings to Date class by judiciously guessing the strings' format

Usage

1
to_ISO_8601(strs, year.left = TRUE, american = FALSE)

Arguments

strs

character string to convert to ISO 8601

year.left

logical give to_ISO_8601 a hint: does the year occur on the left TRUE or on the right FALSE

american

logical does the string follow the bizarre American convention for writing dates, viz. MM-DD-YYYY

Value

Date vector

Author(s)

Thomas P. Harte

See Also

Date, https://xkcd.com/1179

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
   tab<-  tutils:::make_ISO_8601_test_table()
   tab %<>% mutate(`Output`=as.character(NA))

   for (row in 1:nrow(tab)) {
       tab[row, "Output"]<- to_ISO_8601(
           str=tab[row, "Test"],
           year.left=tab[row, "year.left"],
           american=tab[row, "american"]
       ) %>% as.character
   }

   (tab %<>% mutate(`success`=`Expected`==`Output`))

tharte/tutils documentation built on Feb. 11, 2020, 9:17 a.m.