[Rd] Should `as.difftime()` convert integer input to double?
d@v|@ @end|ng |rom r@tud|o@com
Mon Aug 15 00:21:28 CEST 2022
Thanks so much! Do you think `as.difftime()` should retain names? With your
patch, I don't *think* this will retain names anymore:
# This is the released behavior
names(as.difftime(c(x=1), units = "secs"))
#>  "x"
On Sun, Aug 14, 2022 at 12:34 PM Kurt Hornik <Kurt.Hornik using wu.ac.at> wrote:
> >>>>> Bill Dunlap writes:
> Thanks: fixed now in the trunk with c82716.
> > Forcing difftime's payload to be numeric would avoid anomalies like
> >> as.difftime(123456789L, units="secs") * 100L
> > Time difference of NA secs
> > Warning message:
> > In e2 * unclass(e1) : NAs produced by integer overflow
> >> as.difftime(123456789, units="secs") * 100L
> > Time difference of 12345678900 secs
> > Note that there are packages (e.g., fst, a serialization package) which
> > (in C++ code) understand and create difftimes with integer payloads, so
> > may have trouble completely getting rid of such things.
> > -Bill
> > On Tue, Aug 9, 2022 at 11:26 AM Davis Vaughan <davis using rstudio.com> wrote:
> >> 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)
> >> #>  "integer"
> >> x <- as.difftime(1, units = "secs")
> >> typeof(x)
> >> #>  "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
> >> method, which implies something about what the underlying storage type
> >> 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
> >> helper). Even `.Date(1L) - .Date(1L)` produces a difftime with double
> >> storage.
> >> - `seq.Date()` used to be able to produce dates with integer storage,
> >> as of recently even that edge case has been altered to always produce
> >> 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.
> >> Thanks,
> >> Davis
> >> [[alternative HTML version deleted]]
> >> ______________________________________________
> >> R-devel using r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> > [[alternative HTML version deleted]]
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
[[alternative HTML version deleted]]
More information about the R-devel