You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use read_tsv() to read a file which contains quotes escaped by doubling (which is the default in write_tsv()) instead of the quotes being un-escaped you get strings with two quotes. If a file goes through multiple read/write cycles you end up with increasingly large sequences of quotes.
df1<-tibble::tribble(
~A, ~B,
"String", 1,
"String with 'single quotes'", 2,
'String with "double quotes"', 3
)
readr::write_tsv(df1, "file1.tsv")
df2<-readr::read_tsv("file1.tsv", col_types="cd")
waldo::compare(df1, df2)
#> old vs new#> A#> old[1, ] String #> old[2, ] String with 'single quotes' #> - old[3, ] String with "double quotes" #> + new[3, ] String with ""double quotes""#> #> old$A | new$A #> [1] "String" | "String" [1]#> [2] "String with 'single quotes'" | "String with 'single quotes'" [2]#> [3] "String with \"double quotes\"" - "String with \"\"double quotes\"\"" [3]readr::write_tsv(df2, "file2.tsv")
df3<-readr::read_tsv("file2.tsv", col_types="cd")
waldo::compare(df1, df3)
#> old vs new#> A#> old[1, ] String #> old[2, ] String with 'single quotes' #> - old[3, ] String with "double quotes" #> + new[3, ] String with """"double quotes""""#> #> old$A vs new$A#> "String"#> "String with 'single quotes'"#> - "String with \"double quotes\""#> + "String with \"\"\"\"double quotes\"\"\"\""
I can't seem to get this to read in even when I set all the options that I think should make it work. And look at what happens to b — it gets a quote on one side.
hadley
added
bug
an unexpected problem or unintended behavior
and removed
feature
a feature request or enhancement
labels
Jul 31, 2023
When you use
read_tsv()
to read a file which contains quotes escaped by doubling (which is the default inwrite_tsv()
) instead of the quotes being un-escaped you get strings with two quotes. If a file goes through multiple read/write cycles you end up with increasingly large sequences of quotes.Created on 2022-05-06 by the reprex package (v2.0.1)
Session info
You can avoid this by setting
escape
inwrite_tsv()
but would it make sense to have a similar argument forread_tsv()
that does this in reverse?The text was updated successfully, but these errors were encountered: