Skip to content

different quoting behavior, depending on whitespace  #668

Description

@ijlyttle

Sometimes I will write out a small csv by hand - by habit I will put a space after a comma:

"foo", "bar"
"a", "b"

When I read_csv() this, it parses inconsistently.

However, if I take out the whitespace, it parses as I expect:

"foo","bar"
"a","b"

Reprex:

library("readr")

read_csv('"foo","bar"\n"a","b"\n')
#> # A tibble: 1 × 2
#>     foo   bar
#>   <chr> <chr>
#> 1     a     b

read_csv('"foo", "bar"\n"a", "b"\n')
#> # A tibble: 1 × 2
#>     foo `"bar"`
#>   <chr>   <chr>
#> 1     a     "b"

Does this rise to the level of bug? Also, may be similar to #238.

Activity

  1. jennybc commented on Aug 26, 2017

    @jennybc
    Member

    I'm running up against this too. It's especially damaging if you're using the quotes to protect embedded commas. Also: something is off with the printing of the problems?

    library(readr)
    read.csv(text = 'x,y\n1,\"hi,there\"\n3,4')
    #>   x        y
    #> 1 1 hi,there
    #> 2 3        4
    read_csv('x,y\n1,\"hi,there\"\n3,4')
    #> # A tibble: 2 x 2
    #>       x        y
    #>   <int>    <chr>
    #> 1     1 hi,there
    #> 2     3        4
      
    read.csv(text = 'x,y\n1, \"hi,there\"\n3,4')
    #>   x         y
    #> 1 1  hi,there
    #> 2 3         4
    read_csv('x,y\n1, \"hi,there\"\n3,4')
    #> Warning in rbind(names(probs), probs_f): number of columns of result is not
    #> a multiple of vector length (arg 2)
    #> Warning: 1 parsing failure.
    #> row # A tibble: 1 x 5 col     row   col  expected    actual         file expected   <int> <chr>     <chr>     <chr>        <chr> actual 1     1  <NA> 2 columns 3 columns literal data file # A tibble: 1 x 5
    #> # A tibble: 2 x 2
    #>       x      y
    #>   <int>  <chr>
    #> 1     1 "\"hi"
    #> 2     3      4
  2. added
    bugan unexpected problem or unintended behavior
    on Dec 7, 2017
  3. ijlyttle commented on Dec 11, 2017

    @ijlyttle
    ContributorAuthor

    @jimhester Thanks!

  4. lock commented on Sep 25, 2018

    @lock

    This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

  5. locked and limited conversation to collaborators on Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions