[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")
#> [1] "integer"

x <- as.difftime(1, units = "secs")
#> [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

- `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.

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.


	[[alternative HTML version deleted]]

More information about the R-devel mailing list