From g@bembecker @end|ng |rom gm@||@com  Tue Mar  5 23:33:28 2019
From: g@bembecker @end|ng |rom gm@||@com (Gabriel Becker)
Date: Tue, 5 Mar 2019 14:33:28 -0800
Subject: [Rd] as.Date(Inf) displays as 'NA' but is actually 'Inf'
In-Reply-To: <6d06f8f8-828b-4510-6024-908bc6f5336f@rwhite.no>
References: <6d06f8f8-828b-4510-6024-908bc6f5336f@rwhite.no>
Message-ID: <CAD4oTHF0m1taDehMuo6B01L0SyFxjRGBJfFr55QSn0cLfkfuMQ@mail.gmail.com>

Richard,

Well others may chime in here, but from a mathematical point of view, the
concept of "infinite days from right now" is well-defined, so it maybe a
"valid" date in that sense, but what day and month it will be (year will be
Inf) are indeterminate/not well defined. Those are rightfully, NA, it
seems?

I mean you could disallow dates to take Inf at all, ever. I don't feel
strongly one way or the other about that, personally. That said, if inf
dates are allowed, its not clear to me that displaying the "Formatted" date
string as NA, even if the value isn't,  is wrong given it can't be
determined for that "date" is. It could be displayed differently, I
suppose, but all the ones I can think of off the top of my head would be
problematic and probably break lots of formatted-dates parsing code out
there in the wild (and in R, I would guess). Things like displaying
"Inf-NA-NA", or just "Inf". Neither of those are going to handle a
read-write round-trip well, I think.

So my personal don't-really-have-a-hat-in-the-ring opinion would be to
either leave it as is, or force as.Date(Inf, bla) to actually be NA.

Best,
~G

On Tue, Mar 5, 2019 at 12:06 PM Richard White <w at rwhite.no> wrote:

> Hi,
>
> I think I've discovered a bug in base R.
>
> Basically, when using 'Inf' as as 'Date', is is visually displayed as
> 'NA', but R still treats it as 'Inf'. So it is very confusing to work
> with, and can easily lead to errors:
>
> # Visually displays as NA
>  > as.Date(Inf, origin="2018-01-01")
> [1] NA
>
> # Visually displays as NA
>  > str(as.Date(Inf, origin="2018-01-01"))
> Date[1:1], format: NA
>
> # Is NOT NA
>  > is.na(as.Date(Inf, origin="2018-01-01"))
> [1] FALSE
>
> # Is still Inf
>  > is.infinite(as.Date(Inf, origin="2018-01-01"))
> [1] TRUE
>
> This gets really problematic when you are collapsing dates over groups
> and you want to find the first date of a group. Because min() returns
> Inf if there is no data:
>
> # Visually displays as NA
>  > as.Date(min(), origin="2018-01-01")
> [1] NA
> Warning message: In min() : no non-missing arguments to min; returning Inf
>
> # Visually displays as NA
>  > str(as.Date(min(), origin="2018-01-01"))
> Date[1:1], format: NA
> Warning message: In min() : no non-missing arguments to min; returning Inf
>
> # Is not NA
>  > is.na(as.Date(min(), origin="2018-01-01"))
> [1] FALSE
> Warning message: In min() : no non-missing arguments to min; returning Inf
>
> # This is bad!
>  > as.Date(min(), origin="2018-01-01") > "2018-01-01"
> [1] TRUE
> Warning message: In min() : no non-missing arguments to min; returning Inf
>
> Here is my sessionInfo():
>
>  > sessionInfo()
> R version 3.5.0 (2018-04-23)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Debian GNU/Linux 9 (stretch)
> Matrix products: default
> BLAS: /usr/lib/openblas-base/libblas.so.3
> LAPACK: /usr/lib/libopenblasp-r0.2.19.so
>
> locale:
> [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8
> LC_MONETARY=C.UTF-8
> [6] LC_MESSAGES=C LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base loaded via a
> namespace (and not attached):
> [1] compiler_3.5.0 tools_3.5.0 yaml_2.1.19
>
>  > Sys.getlocale()
> [1]
>
> "LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C.UTF-8;LC_COLLATE=C.UTF-8;LC_MONETARY=C.UTF-8;LC_MESSAGES=C;LC_PAPER=C.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C.UTF-8;LC_IDENTIFICATION=C"
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



[Rd] as.Date(Inf) displays as 'NA' but is actually 'Inf'
Gabriel Becker