Skip to contents

Note that THIS FEATURE IS STILL EXPERIMENTAL: we strongly recommend checking a few converted dates manually. This function tries to extract dates from a character vector or a factor. It treats each entry independently, using regular expressions to detect if a date is present, its format, and if successful it converts that entry to a standard Date with the Ymd format (e.g. 2018-01-21). Entries which cannot be processed result in NA. An error threshold can be used to define the maximum number of resulting NA (i.e. entries without an identified date) that can be tolerated. If this threshold is exceeded, the original vector is returned.

Usage

date_guess(x, column_name, quiet = TRUE, orders = NULL)

Arguments

x

A character vector or a factor

column_name

The target column name

quiet

A logical indicating if messages should be displayed to the console (TRUE, default); set to FALSE to silence messages

orders

A list or character vector with the date codes for fine-grained parsing of dates. This allows for parsing of mixed dates. If a list is supplied, that list will be used for successive tries in parsing. When this is not provided (orders = NULL), the function will use the following order defined in the guesser:

list(
  quarter_partial_dates = c("Y", "Ym", "Yq"),
  world_digit_months = c("Yq", "ymd", "ydm", "dmy", "mdy", "myd", "dym",
                         "Ymd", "Ydm", "dmY", "mdY", "mYd", "dYm"),
  world_named_months = c("dby", "dyb", "bdy", "byd", "ybd", "ydb",
                         "dbY", "dYb", "bdY", "bYd", "Ybd", "Ydb"),
  us_format = c("Omdy", "YOmd")
)

Value

A list of following two elements: a vector of the newly reformatted dates and a data frame with the date values that were converted from more than one format. If all values comply with only one format, the later element will be NULL.