Skip to content

write_tsv() needs the option to never quote any fields #993

Description

@NikKrieger

This is in the spirit of @cboettig's comment in #844:

@jimhester I think this issue also impacts write_tsv()? Looks like readr cannot write a IANA valid tsv file with quoted text, since there's not even an option(?) to not double-quote quotations?

Indeed, the main feature of the .tsv is that tab characters are disallowed in fields, thereby making quoting totally unnecessary.

So, I would argue that the problem isn't that write_tsv() needs an "option(?) to not double-quote quotations," but rather that write_tsv() needs an option to never quote anything. Setting quote_escape = "none" does not accomplish this, though I realize that this wasn't the intent behind it:

library(tidyverse)

foo <- 
  tribble(
    ~name, ~catch_phrase,
    "Jane", 'I am 72" tall.',
    "John", '"No" means "no."'
  )

tmp <- tempfile()

write_tsv(foo, path = tmp, quote_escape = "none")

writeLines(readLines(tmp))

#> name	catch_phrase
#> Jane	"I am 72" tall."
#> John	""No" means "no.""

One has to resort to write.table() in order to obtain an IANA-compatible .tsv file out of a data frame like foo:

tmp_base <- tempfile()
write.table(foo, file = tmp_base, quote = FALSE, sep = "\t", row.names = FALSE)
writeLines(readLines(tmp_base))

#> name	catch_phrase
#> Jane	I am 72" tall.
#> John	"No" means "no."

So for write_tsv(), there should be an option to never quote any fields. Perhaps there could also be an option to throw an error if a tab character is detected, but that's not my main concern in this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions