Skip to content

Infinite dates are not parsed correctly #1458

Open
@keesdeschepper

Description

@keesdeschepper

What seems to be new in R is that infinite dates are formatted as "Inf" when coerced to string. This causes problems in write-read roundtrips, as readr's parser guessing does not accept "Inf" as a valid date:

library(tidyverse)
output <- format_csv(tibble(x = lubridate::as_date(c(0, Inf))))
output
#> [1] "x\n1970-01-01\nInf\n"
input <- suppressMessages(read_csv(output))
attr(input, "spec")
#> cols(
#>   x = col_character()
#> )

Assuming this is correct there are some solutions. Personally I would prefer a change on the read side, where read_delim etc. accept "Inf" and "-Inf" as valid dates. It violates iso8601, but it would be nice to preserve the distinction between missing dates and infinite dates.

If that's not an option, there are also solutions on the write side.

  1. output infinite dates as something more in line with iso8601 like "9999-13-00";
  2. output as NA (which is functionally as it was before)
  3. give an error if infinite dates are written

Some parameter to control this is of course possible, but the important choice then, in my view, is what the default option would be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviordatetime 📆

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions