0

According to these SO questions here and here (and my own painful experience), read.table and read.csv seem incapable of ingesting escaped quotes that are within quoted text.

Ideally, I'd like to use the same function to ingest both:

"column value 1","column \" value 2", NA, "column value 4"

And

column value 1, column \" value 2, NA, column value 4

Are there any alternatives to these functions that can read in escaped quotes within quoted text in R?

The solutions provided to the previous questions seem to require dangerous assumptions about what else is in the text (i.e., it's always quoted, or it never has single quotes), and having a function that can process CSVs with or without quoted columns would be hugely helpful.

Community
  • 1
  • 1
canary_in_the_data_mine
  • 2,193
  • 2
  • 24
  • 28
  • Use read_delim from readr. See my answer here https://stackoverflow.com/a/56299262/3163618 – qwr May 24 '19 at 20:42

1 Answers1

-2

Can you use a more modern, type-safe, efficient data interchange format besides the half-century old ill-defined CSV format? Protocol Buffers, JSON, or even XML would all provide significant advantages to CSV. CSV is simply not a well-defined format but rather an ad-hoc informal spec and so without more information about what is generating your input CSV files it is impossible to describe an R function that would reliably parse it.

MurrayStokely
  • 345
  • 2
  • 6
  • That is not a helpful answer. If the data is old, it is as it is and we have to work with the given format. –  Nov 13 '15 at 08:52