Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse datetime with a space in format #1295

Closed
hongyuanjia opened this issue Sep 6, 2021 · 2 comments
Closed

Failed to parse datetime with a space in format #1295

hongyuanjia opened this issue Sep 6, 2021 · 2 comments

Comments

@hongyuanjia
Copy link

Possibly related to #1276.

# development version
library(readr)
packageVersion("readr")
#> [1] '2.0.1.9000'

fmt_space <- "%d/%m/%y %H:%M"
fmt_nospace <- "%d/%m/%y%H:%M"

# both work using parse_datetime()
with_edition(1, readr::parse_datetime("1/9/19 0:00", fmt_space))
#> [1] "2019-09-01 UTC"
with_edition(2, readr::parse_datetime("1/9/19 0:00", fmt_space))
#> [1] "2019-09-01 UTC"
with_edition(1, readr::parse_datetime("1/9/19 0:00", fmt_nospace))
#> [1] "2019-09-01 UTC"
with_edition(2, readr::parse_datetime("1/9/19 0:00", fmt_nospace))
#> [1] "2019-09-01 UTC"

# create example data
s <- c("datetime, value", "1/9/19 0:00, 1")
f <- tempfile(fileext = "csv")
writeLines(s, f)

# both work with edition 1
with_edition(1,
  readr::read_csv(
    f,
    col_types = cols(
      col_datetime(fmt_space),
      col_integer()
    )
  )
)
#> # A tibble: 1 x 2
#>   datetime            value
#>   <dttm>              <int>
#> 1 2019-09-01 00:00:00     1
with_edition(1,
  readr::read_csv(
    f,
    col_types = cols(
      col_datetime(fmt_nospace),
      col_integer()
    )
  )
)
#> # A tibble: 1 x 2
#>   datetime            value
#>   <dttm>              <int>
#> 1 2019-09-01 00:00:00     1

# however, it fails in edition 2 if there is a space
with_edition(2,
  readr::read_csv(
    f,
    col_types = cols(
      col_datetime(fmt_space),
      col_integer()
    )
  )
)
#> Warning: One or more parsing issues, see `problems()` for details
#> # A tibble: 1 x 2
#>   datetime            value
#>   <dttm>              <int>
#> 1 NA                      1

# without spacing, it works
with_edition(2,
  readr::read_csv(
    f,
    col_types = cols(
      col_datetime(fmt_nospace),
      col_integer()
    )
  )
)
#> # A tibble: 1 x 2
#>   datetime            value
#>   <dttm>              <int>
#> 1 2019-09-01 00:00:00     1

Created on 2021-09-06 by the reprex package (v2.0.0)

@jimhester
Copy link
Collaborator

This should be fixed by installing the latest version of vroom (1.5.5)

@hongyuanjia
Copy link
Author

Thanks! Just checked and the problem goes away after updating vroom to v1.5.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants