Open ralmond opened 2 years ago
The documentation for unbox()
says
Arguments
x
atomic vector of length 1, or data frame with 1 row.
Since a POSIXlt
object is not an atomic vector of length 1 (it's a list of length 11), I'd say this function is documented and working as expected?
It may be working as documented, but it is not working as expected. In particular, I tend to think of a POSIXt object in the same way whether it is a POSIXlt or POSIXct object. The fact that the current unbox
works differently for the two is unexpected, and forces the developer to think about the underlying representation of the object.
Also, normally both POSIXct and POSIXlt objects are translated into the same format depending on the POSIXt
argument to toJSON
. So treating the POSIXct
object differently in unbox
is a bit unexpected.
FInally, it is literally a 3-line patch; I've already submitted the pull request.
Here is a quick sample which shows the bug:
POSIXlt works as expected:
However, POSIXct fails
I can work around by calling
jsonlite:::as.scalar
on the internal object, but I'm then depending on undocumented internals.This issue may be at the heart of #192 and #194.