The function sdtm::create_iso8601() currently assigns a custom S3 class "iso8601" to its return value:
class(iso8601) <- "iso8601"
While a print.iso8601() method is implemented, it does not provide additional behaviour beyond printing the underlying character vector. However, assigning this class causes downstream interoperability issues with base R date-time conversion functions.
In particular, objects of class "iso8601" cannot be converted using standard generics such as as.Date(), as.POSIXct(), or as.POSIXlt().
Reproducible example
dtc <- create_iso8601(c("20200102"), .format = "ymd")
as.Date(dtc)
# Error in as.Date.default():
# do not know how to convert 'dtc' to class “Date”
as.POSIXct(dtc)
# Error in as.POSIXlt.default():
# do not know how to convert 'x' to class “POSIXlt”
as.POSIXlt(dtc)
# Error in as.POSIXlt.default():
# do not know how to convert 'dtc' to class “POSIXlt”
The same value works immediately if the class is removed:
as.Date(unclass(dtc))
# [1] "2020-01-02"
as.Date(as.character(dtc))
# [1] "2020-01-02"
Why the "iso8601" class adds no practical value
The returned object is still a character vector containing ISO 8601–formatted values. However:
- The "iso8601" class does not define semantics beyond what is already encoded in the string.
- The only implemented method is print.iso8601(), which does not change values or expose additional behaviour.
- All standard date-time functionality in R (as.Date(), as.POSIXct(), arithmetic, comparisons) operates on base character inputs, not on this custom class.
In practice, adding a class means that every downstream date-related operation would require a dedicated S3 method
This leads to unnecessary friction in downstream workflows, especially when ISO 8601 strings are immediately converted to numeric or date-time representations.
Suggested change
Remove the custom class assignment entirely:
class(iso8601) <- "iso8601"
and return a plain character vector.
The function
sdtm::create_iso8601()currently assigns a custom S3 class "iso8601" to its return value:class(iso8601) <- "iso8601"While a print.iso8601() method is implemented, it does not provide additional behaviour beyond printing the underlying character vector. However, assigning this class causes downstream interoperability issues with base R date-time conversion functions.
In particular, objects of class "iso8601" cannot be converted using standard generics such as as.Date(), as.POSIXct(), or as.POSIXlt().
Reproducible example
The same value works immediately if the class is removed:
Why the "iso8601" class adds no practical value
The returned object is still a character vector containing ISO 8601–formatted values. However:
In practice, adding a class means that every downstream date-related operation would require a dedicated S3 method
This leads to unnecessary friction in downstream workflows, especially when ISO 8601 strings are immediately converted to numeric or date-time representations.
Suggested change
Remove the custom class assignment entirely:
class(iso8601) <- "iso8601"and return a plain character vector.