From ch|r|com @end|ng |rom goog|e@com  Tue Sep  7 19:44:03 2021
From: ch|r|com @end|ng |rom goog|e@com (Michael Chirico)
Date: Tue, 7 Sep 2021 10:44:03 -0700
Subject: [Rd] Should seq.Date() return double storage?
Message-ID: <CAD7Bkx8G-74PxQpchi2+ejTEKzOVaPih2o13pmbhmRRo9FTCLg@mail.gmail.com>

today <- Sys.Date()
typeof(today)
# [1] "double"
typeof(seq(today, by=1, length.out=2))
# [1] "integer"

Clearly minor as it doesn't seem to have come up before (e.g. coercion
to numeric will happen automatically whenever fractional dates are
needed); I only noticed because of a test using identical failing:

identical(
  seq(today, by=1, length.out=10),
  today + 0:9
)
# [1] FALSE

It's easy in this case to fix the test using coercion, but this could
(and did in practice) come up at deeper levels of nesting that become
more onerous to handle. And using all.equal() comes with its own
tradeoffs.

The fix would be easy enough -- at a glance there are two usages of
.Date(seq.int(...)) in seq.Date() that could be replaced by
.Date(as.numeric(seq.int(...))).

Mike C



[Rd] Should seq.Date() return double storage?
Michael Chirico