Skip to content

The quote argument in read_tsv might not work correctly #1254

@jpquast

Description

@jpquast

I am trying to read a text file into R, that sometimes has quoted names in a rows and it only contains one column. This can look like the following:

first row
second "row"
"third" row
"fourth row"

If I try reading this file using the read_tsv() function (because rows never contain tabs, but might contain commas), it reads it in the following way:

read_tsv("my_file.tsv", 
col_names = FALSE, 
show_col_types = FALSE, 
progress = FALSE, 
quote = "")
# A tibble: 4 x 1
  X1              
  <chr>           
1 "first row"     
2 "second \"row\""
3 "third row"     
4 "fourth row"  

What I would expect from the argument quote = "" is however, that it would keep and escape all the quotes.
If I use the function read_delim() this is done correctly:

read_delim("my_file.tsv", 
delim = "\t", 
col_names = FALSE, 
show_col_types = FALSE, 
progress = FALSE, 
quote = "")
  X1               
  <chr>            
1 "first row"      
2 "second \"row\"" 
3 "\"third\" row"  
4 "\"fourth row\" "

It seems to me that the quote argument does not do anything when used in the read_tsv() function as compared to the read_delim() function. Maybe I made a mistake here and this is expected, but to me this does not seem as it is intended.
Help would be greatly appreciated!

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