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

problems() not pulling up the exact text of a parsing failure #548

Closed
kendonB opened this issue Nov 6, 2016 · 4 comments
Closed

problems() not pulling up the exact text of a parsing failure #548

kendonB opened this issue Nov 6, 2016 · 4 comments
Labels

Comments

@kendonB
Copy link

@kendonB kendonB commented Nov 6, 2016

The example:

library(tidyverse)
x <- tribble(
  ~unit, ~value,
  "a"  ,    "1",
  "b"  ,     "(NA)")
write_tsv(x, path = "test.tsv")

Now try and parse with the incorrect NA specification (in the real application it's not obvious exactly what represents NA).

new_x <- read_tsv("test.tsv",
                  na = "",
                  col_types = cols(
                      unit = col_character(),
                      value = col_number()
                    ))
file.remove("test.tsv")

problems(new_x)
# A tibble: 1 × 4
#     row   col expected actual
#   <int> <chr>    <chr>  <chr>
# 1     2 value a number       

I would have expected this to come up:

# A tibble: 1 × 4
#   row     col expected actual
# <int>   <chr>    <chr>  <chr>
# 1   2   value a number   (NA) 

Is this the expected behavior?

@hadley hadley added bug read labels Dec 22, 2016
@hadley
Copy link
Member

@hadley hadley commented Dec 22, 2016

Simpler reprex:

problems(read_tsv("x\n1\nx", na = "", col_types = "n"))

This is ok:

problems(read_tsv("x\n1\nx", na = "", col_types = "d"))

So probably a buglet in the number collector.

@kendonB
Copy link
Author

@kendonB kendonB commented Feb 24, 2017

Thanks for the fix!

I found another case which fails, even after the fix:

problems(read_tsv("(-)\n1\n(-)", na = "", col_types = "n"))
@jimhester
Copy link
Member

@jimhester jimhester commented Feb 24, 2017

Looks correct to me, what do you expect the output to be?

library(readr)
problems(read_tsv("(-)\n1\n(-)", na = "", col_types = "n"))
#> # A tibble: 1 × 4
#>     row   col expected actual
#>   <int> <chr>    <chr>  <chr>
#> 1     2   (-) a number      -
@kendonB
Copy link
Author

@kendonB kendonB commented Feb 25, 2017

@lock lock bot locked and limited conversation to collaborators Sep 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants