Description Usage Arguments Value Examples
View source: R/extract_datetime.R
Extract and parse date-times within strings such as filenames. Currently only handles format "yyyy?mm?dd?HH?MM?(SS)", where "?" represents an optional space or punctuation character, and the seconds slot (SS) is optional.
1 2 3 4 5 6 7 | extract_datetime(
x,
remove_path = TRUE,
year_min = 2000,
year_max = as.integer(format(Sys.Date(), "%Y")),
if_multiple = "use_last"
)
|
x |
Vector of strings such as file names |
remove_path |
Logical indicating whether to strip file paths from |
year_min |
Minimum year value expected. Targeting an expected year range
helps avoid false positive matches to number sequences that are not dates.
Defaults to |
year_max |
Maximum year value expected. Defaults to the current year
based on |
if_multiple |
If multiple date-times within a string, return only the first ("use_first"), or only the last ("use_last"). Defaults to "use_last". |
Vector of date-times (of class POSIXct/POSIXt). Returns NA when no date-time found within a given string.
1 2 3 4 5 6 7 8 9 10 11 | files <- c(
"~/Documents/2020-02-01/myfile-2020-06-30-1230.csv",
"2020_06_30_052051_Database_Complete_v1230.csv",
"~/Desktop/data__cleaned1.xlsx",
"~/Desktop/data__cleaned__2020-07-01_16-25.xlsx",
"22062020-covid19-cases.xlsm",
"/Documents/2015/PhD.Data.20091020_1247.Final.xls",
"/exports/2015-03-05/export-2015-03-05_1352.xls"
)
extract_datetime(files)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.