It's probably gonna be a stupid question, but I can't find the answer quickly and I'm too curious to give up even if late.
In essence, why 1L:3L and letters are both vectors
> is.vector(1:3)
[1] TRUE
> is.vector(letters)
[1] TRUE
and a sequence of dates is not?
x <- structure(1:3, class = "Date")
> is.vector(x)
[1] FALSE
From ?vector
The atomic modes are "logical", "integer", "numeric" (synonym "double"),
"complex", "character" and "raw".
Fine, clear, even though x is atomic...
> is.atomic(x)
[1] TRUE
So, what makes a dates vector not to be read as vector? (in means of as.vector()) and what is there behind this difference?
This question comes from a try to use embed with dates which fails cause it wants vector or array. But from a structural point of view I can't see the difference between 1L:10L and structure(1L:10L, class="Date")
A few of my comments collected together in an answer:
So, the documentation also says:
is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise.
So as discussed in this pervious answer, is.vector is more like a check on whether a vector has attributes other than names, which certainly may not be obvious.
As for why embed behaves the way it does, I'm not sure. It could potentially use is.atomic instead, but you'd then have to check for lists separately to achieve the same behavior. There may be some other edge cases I'm overlooking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With