From m@echler @ending from @t@t@m@th@ethz@ch  Mon Jun 11 11:12:23 2018
From: m@echler @ending from @t@t@m@th@ethz@ch (Martin Maechler)
Date: Mon, 11 Jun 2018 11:12:23 +0200
Subject: [Rd] 
 Date class shows Inf as NA; this confuses the use of is.na()
In-Reply-To: <CAO1zAVbD-aB-ou2Tef5C9bMnvCW8mi-4igmnera7T=AUj74-YA@mail.gmail.com>
References: <CAGg4omXVJj3vnK1+Z4zaHeuQ5Q+GjsOcvY22D13-okpjzWCsuA@mail.gmail.com>
 <710BDF90-B13A-47CE-980B-9276293C7E45@llnl.gov>
 <CAGg4omUa-ZU5hrKzj1a6e154bTOCge_T8kahcwEzFSpPxXG3tg@mail.gmail.com>
 <CAO1zAVZ0Wwpqm75JGCNz1YVvBC2FSLL8byBEPLa1-7EQjP09UQ@mail.gmail.com>
 <CAO1zAVbD-aB-ou2Tef5C9bMnvCW8mi-4igmnera7T=AUj74-YA@mail.gmail.com>
Message-ID: <23326.15607.903724.181995@stat.math.ethz.ch>

>>>>> Joris Meys 
>>>>>     on Sat, 9 Jun 2018 13:45:21 +0200 writes:

    > And now I've seen I copied the wrong part of ?is.na
    >> The default method for is.na applied to an atomic vector
    >> returns a
    > logical vector of the same length as its argument x,
    > containing TRUE for those elements marked NA or, for
    > numeric or complex vectors, NaN, and FALSE otherwise.

    > Key point being "atomic vector" here.

and a Date vector *is* atomic .. (so I'm confused about what
that issue is .. but read one.


    > On Sat, Jun 9, 2018 at 1:41 PM, Joris Meys
    > <jorismeys at gmail.com> wrote:

    >> Hi Werner,
    >> 
    >> on ?is.na it says:
    >> 
    >> > The default method for anyNA handles atomic vectors
    >> without a class and NULL.
    >> 
    >> I hear you, and it is confusing to say the least. Looking
    >> deeper, the culprit seems to be in the conversion of a
    >> Date to POSIXlt prior to the formatting:
    >> 
    >> > x <- as.Date(Inf,origin = '1970-01-01')
    >> > is.na(as.POSIXlt(x)) [1] TRUE
    >> 
    >> Given this implicit conversion, I'd argue that as.Date
    >> should really return NA as well when passed an infinite
    >> value. The other option is to provide an is.na method for
    >> the Date class, which is -given is.na is an internal
    >> generic- rather trivial:
    >> 
    >> > is.na.Date <- function(x) is.na(as.POSIXlt(x)) 
    >> > is.na(x) [1] TRUE
    >> 
    >> This might be a workaround for your current problem
    >> without needing changes to R itself. But this will give a
    >> "wrong" answer in the sense that this still works:
    >> 
    >> > Sys.Date() - x Time difference of -Inf days
    >> 

    >> I personally would go for NA as the "correct" date for an
    >> infinite value, but given that this will have
    >> implications in other areas, there is a possibility of
    >> breaking code and it should be investigated a bit further
    >> imho.  Cheers Joris

Indeed.  I could argue it is wrong to treat '+/- Inf' as NA for
dates (as well as for date times), because the Inf *does*
contain information in some sense:

     Infinitely far in the future
vs   Infinitely far in the past

which may make sense in some case ... in the same sense +Inf and
-Inf do make sense for numbers in some cases.

Martin



[Rd] Date class shows Inf as NA; this confuses the use of is.na()
Martin Maechler