[Rd] Confusing print method for Inf dates

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Oct 22 00:18:03 CEST 2015

On Wed, Oct 21, 2015 at 4:57 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
> x <- as.Date(Inf, origin = "1970-01-01")
> x
> #> [1] NA
> str(x)
> #>  Date[1:1], format: NA
> unclass(x)
> #> [1] Inf
> It's not clear what the correct behaviour is. The documentation for
> ?Date has: "It is intended that the date should be an integer,", which
> suggests that -Inf and Inf are not valid dates. But if that's true the

You omitted the second half of the sentence, which contains important
information.  The entire sentence is, "It is intended that the date
should be an integer, but this is not enforced in the internal
representation."  Since it's not enforced internally, it doesn't
necessarily follow that non-integer values are invalid dates.  The
rest of the paragraph describes how fractional (internal) dates can be

Both ?format.Date and ?strptime say that 'NA' dates/times are printed
as NA_character_.  It might be clearer to say that "invalid"
dates/times are printed as NA_character_.

> behaviour for max.Date() needs some thought:
> max(as.Date(NA), na.rm = TRUE)
> #> Warning in max.default(structure(NA_real_, class = "Date"), na.rm = TRUE):
> #> no non-missing arguments to max; returning -Inf
> #> [1] NA
> If dates are integers, then there is no date that is smaller than all
> other dates, so it's not clear what max() should return - NA?
But they're not integers in the strict sense.

> Hadley
> --
> http://had.co.nz/
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

More information about the R-devel mailing list