Using the mdy function to parse strings into date values may result in wrong dates when the day number is provided as text.
For instance, in the snippet below I would expect the string to either be parsed as "2022-11-03" or to be coerced to NA.
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
mdy("November third, 2022")
#> [1] "2022-11-20"
Using the
mdy
function to parse strings into date values may result in wrong dates when the day number is provided as text. For instance, in the snippet below I would expect the string to either be parsed as"2022-11-03"
or to be coerced toNA
.Created on 2022-11-03 by the reprex package (v2.0.1)
What happens instead is that, apparently, the string
"third"
is ignored, and the first two digits of the year are used as the day.