title: Read CSV file with embedded double quotes and commas
body: <p>I am trying to read a dirty CSV file using the fread() function from the data.table package but have a problem with embedded double quotes and commas in the string values, that is, unescaped double quotes present in a quoted field. The following example data illustrates my problem. It consists of 3 lines/rows and 6 columns, with the first line containing the column names:</p>
  
  <pre><code>"SA","SU","CC","CN","POC","PAC"
  "NE","R","000","H "B", O","1","8"
  "A","A","000","P","E,5","8"
  </code></pre>
  
  <p>The first problem is in line 2 which has an embedded pair of double quotes and a comma: <code>"H "B", O"</code>. The second problem is in line 3 which has a comma within the double quotes: <code>"E,5"</code>. I have tried the following:</p>
  
  <p><strong>Attempt 1</strong></p>
  
  <pre><code>library(data.table)
  x1 &lt;- fread(file = "example.csv", quote = "\"")
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>&gt; x1
       V1 "SA" "SU"   "CC" "CN" "POC" "PAC"
  1: "NE"  "R"    0 "H "B"   O"   "1"     8
  2:  "A"  "A"    0    "P"   "E    5"     8
  </code></pre>
  
  <p>Message: </p>
  
  <blockquote>
    <p>Found and resolved improper quoting in first 100 rows. If the fields
    are not quoted (e.g. field separator does not appear within any
    field), try quote="" to avoid this warning.Detected 6 column names but
    the data has 7 columns (i.e. invalid file). Added 1 extra default
    column name for the first column which is guessed to be row names or
    an index. Use setnames() afterwards if this guess is not correct, or
    fix the file write command that created the file to create a valid
    file.</p>
  </blockquote>
  
  <p>Conclusion: the result is incorrect because it adds a new column <code>V1</code>. </p>
  
  <p><strong>Attempt 2</strong></p>
  
  <pre><code>x2 &lt;- fread(file = "example.csv", quote = "")
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>&gt; x2
       V1 "SA"  "SU"   "CC" "CN" "POC" "PAC"
  1: "NE"  "R" "000" "H "B"   O"   "1"   "8"
  2:  "A"  "A" "000"    "P"   "E    5"   "8"
  </code></pre>
  
  <p>Message:</p>
  
  <blockquote>
    <p>Detected 6 column names but the data has 7 columns (i.e. invalid
    file). Added 1 extra default column name for the first column which is
    guessed to be row names or an index. Use setnames() afterwards if this
    guess is not correct, or fix the file write command that created the
    file to create a valid file.</p>
  </blockquote>
  
  <p>Conclusion: the result is incorrect because it adds a new column <code>V1</code>..</p>
  
  <p><strong>Solution?</strong></p>
  
  <p>What I am looking for is a way to get an output similar to </p>
  
  <pre><code>&gt; x3
     SA SU CC       CN POC PAC
  1: NE  R  0 H 'B', O   1   8
  2:  A  A  0        P E,5   8
  </code></pre>
  
  <p>preferably using fread(), but other suggestions are welcome. </p>