globalgov / messydates

R package for Extended Date/Time Format (EDTF)
https://globalgov.github.io/messydates
Other
15 stars 1 forks source link

Subsetting and other basic vector methods #77

Closed WerthPADOH closed 7 months ago

WerthPADOH commented 1 year ago

Some basic vector methods (subsetting, c, and data.frame-related) for messy dates are missing. This is a problem for common use cases:

Current behavior:

x <- as_messydate(c("2012-01-01", "2012-01-02"))

# Subsetting drops the class
class(x[1])
# [1] "character"

# Combining with another messy date drops the class
y <- c(x, as_messydate("2000-02-28"))
class(y)
# [1] "character"

# Can insert invalid dates, and they remain as-is
x[2] <- "not a date"
x
# 'mdate' chr [1:2] "2012-01-01" "not a date"

# Can't create a new data.frame with a messy date column
data.frame(a = x)
# Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
#   cannot coerce class ‘"mdate"’ to a data.frame

I've written the methods and can make a pull request if you'd like.

henriquesposito commented 1 year ago

This is great @WerthPADOH , thank you very much for the help! Yes, could you please open a PR with these changes? Thank you once again.