extract_date: Extract the date from a charcter string

Description Usage Arguments Author(s) Examples

View source: R/extract_date.R

Description

This function is used to extract a date from a character vector, using a user-provided date parser. It first uses regular expressions to isolate potential dates from the character strings, and then applies the parser (by default, lubridate::ymd) to return a Date object. The function only handles dates provided as numbers.

Usage

1
extract_date(x, date_parser = lubridate::ymd)

Arguments

x

a character string containing dates to be extracted

date_parser

a function to extract dates from character strings; we recommend using lubridate's function there, e.g. ymd (any date format with year, month, day) or dmy (any format using day, month, year); defaults to lubridate::ymd

Author(s)

Thibaut Jombart thibautjombart@gmail.com

Examples

1
2
3
4
5
x <- c("contacts_2017-10-29.xlsx",
       "some text! 2020 01 12",
       "2019.1.13 - linelist",
       "no date here :-/ ") 
extract_date(x)

reconhub/rfextras documentation built on Aug. 16, 2021, 5:25 a.m.