[Rd] Should `as.difftime()` convert integer input to double?
Davis Vaughan
d@v|@ @end|ng |rom r@tud|o@com
Tue Aug 9 20:26:08 CEST 2022
Hi all,
Currently, `as.difftime()` with an integer input will produce a difftime
object that internally is built on an integer vector, i.e.:
x <- as.difftime(1L, units = "secs")
typeof(x)
#> [1] "integer"
x <- as.difftime(1, units = "secs")
typeof(x)
#> [1] "double"
I feel like difftime objects should always be built on *double* vectors.
There are a few reasons I feel like this should be true:
- There is an `as.double.difftime()` method, but no `as.integer.difftime()`
method, which implies something about what the underlying storage type is
assumed to be.
- AFAIK, there is no other way to produce a difftime object with integer
storage using the exposed API (aside from abusing the internal .difftime()
helper). Even `.Date(1L) - .Date(1L)` produces a difftime with double
storage.
- `seq.Date()` used to be able to produce dates with integer storage, but
as of recently even that edge case has been altered to always produce dates
with double storage. So a change to also force difftime to have double
storage would feel consistent with that.
https://github.com/wch/r-source/commit/0762ee983813c4df9b93f6b5ee52c910dcd3ab39
It looks like a patch to `as.difftime()` would be fairly straightforward
(i.e. ensuring that integer input is coerced to double), so I'd be happy to
attempt one if someone else agrees that this should be changed.
Thanks,
Davis
[[alternative HTML version deleted]]
More information about the R-devel
mailing list