reformat_date: Recognize dates formatted as 8 consecutive integers and...

View source: R/util_infer_metadata_from_file.R

reformat_dateR Documentation

Recognize dates formatted as 8 consecutive integers and rewrite them as "-" delimited

Description

If input array of strings are all encoding exactly 8 integers, test if each represents a valid dates. If so, add separation chars.

Usage

reformat_date(x)

Arguments

x

array of strings representing dates, see examples

Details

Implementation is intentionally simplified, only needs to catch most obvious cases (so ignore potential dates denoted as 6 numbers, etc.) Hardcoded "oldest year" is 1990, serves our use-case and adds robustness (we use this function in a scenario where any set of numbers can be supplied, but experiment samples are note likely 20+ years old) For ambiguous dates, e.g. 20102010 (20-10-2010 or 2010-20-10), prioritize year YYYYxxzz over xxzzYYYY

examples; reformat_date(x = c("20200220", "20200221")) reformat_date(x = c("20202002", "20202102")) reformat_date(x = c("11012002", "11022002"))


ftwkoopmans/msdap documentation built on March 5, 2025, 12:15 a.m.