Werner Grundlingh
2018-Jun-08 20:02 UTC
[Rd] Date class shows Inf as NA; this confuses the use of is.na()
In the following example, the date class shows Inf as NA> as_date(Inf, origin = '1970-01-01')[1] NA This is misleading as is.na() reports incorrectly> is.na(as_date(Inf, origin = '1970-01-01'))[1] FALSE The correct approach here would probably to have an Inf (and -Inf) *displayed* rather than NA. [[alternative HTML version deleted]]
MacQueen, Don
2018-Jun-08 21:12 UTC
[Rd] Date class shows Inf as NA; this confuses the use of is.na()
> as_dateError: object 'as_date' not found Must be from some not-named package... But don't confuse the format of an object when printed with its underlying value:> as.Date(Inf,origin = '1970-01-01')[1] NA> str(as.Date(Inf,origin = '1970-01-01'))Date[1:1], format: NA> as.numeric(as.Date(Inf,origin = '1970-01-01'))[1] Inf> is.na(Inf)[1] FALSE> is.na(as.Date(Inf,origin = '1970-01-01'))[1] FALSE> str(as.Date(27,origin = '1970-01-01'))Date[1:1], format: "1970-01-28"> as.numeric(as.Date(27,origin = '1970-01-01'))[1] 27 -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 ?On 6/8/18, 1:02 PM, "R-devel on behalf of Werner Grundlingh" <r-devel-bounces at r-project.org on behalf of wgrundlingh at gmail.com> wrote: In the following example, the date class shows Inf as NA > as_date(Inf, origin = '1970-01-01') [1] NA This is misleading as is.na() reports incorrectly > is.na(as_date(Inf, origin = '1970-01-01')) [1] FALSE The correct approach here would probably to have an Inf (and -Inf) *displayed* rather than NA. [[alternative HTML version deleted]] ______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Werner Grundlingh
2018-Jun-08 21:21 UTC
[Rd] Date class shows Inf as NA; this confuses the use of is.na()
Indeed. as_date is from lubridate, but the same holds for as.Date. The output and it's interpretation should be consistent, otherwise it leads to confusion when programming. I understand that the difference exists after asking a question on Stack Overflow: https://stackoverflow.com/q/50766089/914686 This understanding is never mentioned in the documentation - that an Inf date is actually represented as NA: https://www.rdocumentation.org/packages/base/versions/3.5.0/topics/as.Date So I'm of the impression that the display should be fixed as a first option (thereby providing clarity/transparency in terms of back-end and output), or the documentation amended (to highlight this) as a second option. [[alternative HTML version deleted]]
Seemingly Similar Threads
- Date class shows Inf as NA; this confuses the use of is.na()
- Date class shows Inf as NA; this confuses the use of is.na()
- Date class shows Inf as NA; this confuses the use of is.na()
- New matrix function
- Date class shows Inf as NA; this confuses the use of is.na()