As lubridate already has a handy yq() function for parsing year-quarter "dates", would you consider adding ym(), the equivalent for numeric year-month "dates"?
Date such as this crop up all the time in applied sciences, where the exact date of sampling is not recorded or neccessary or the data have been aggregated to a monthly time step, eg monthly climate anomolies, and provided in that format (i.e. without any day component).
parse_date_time knows how to handle such inputs
> parse_date_time("10/2001", "mY")
[1] "2001-10-01 UTC"
I'm thinking of something along the lines of (I'm new to lubridate so I'm not sure I follow the meaning of the orders argument just yet):
ym <- function (..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME")) {
lubridate:::.parse_xxx(..., orders = "ym", quiet = quiet, tz = tz, locale = locale,
truncated = 0)
}
my <- function (..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME")) {
lubridate:::.parse_xxx(..., orders = "my", quiet = quiet, tz = tz, locale = locale,
truncated = 0)
}
with expected output
> my("10-2001")
[1] "2001-10-01"
> ym("2010-10")
[1] "2010-10-01"
Optionally, accepting an argument fraction (or equivalent) would allow user to control the day part that is added: would return date + days(fraction * days_in_month)?
As lubridate already has a handy
yq()function for parsing year-quarter "dates", would you consider addingym(), the equivalent for numeric year-month "dates"?Date such as this crop up all the time in applied sciences, where the exact date of sampling is not recorded or neccessary or the data have been aggregated to a monthly time step, eg monthly climate anomolies, and provided in that format (i.e. without any day component).
parse_date_timeknows how to handle such inputsI'm thinking of something along the lines of (I'm new to lubridate so I'm not sure I follow the meaning of the
ordersargument just yet):with expected output
Optionally, accepting an argument
fraction(or equivalent) would allow user to control the day part that is added: would returndate + days(fraction * days_in_month)?