title: R <- How to use data.table's fread and fwrite when data contains newlines?
body: <p>I have problems when having to save a data.table object to a file with text columns that can contain new lines or other types of characters.</p>
  
  <p>For example:</p>
  
  <pre><code>x &lt;- data.frame( 
         x = c(1,2,3), 
         y = c("Lorem ipsum dixit", 'the "brown"\nfox', "a|b"),  
         stringsAsFactors = F)
  </code></pre>
  
  <p>I write it to file with:</p>
  
  <pre><code>data.table::fwrite(
       dataset,
       "testfile.tsv",
       sep = "\t",
       na = "NULL",
       quote = TRUE,
       eol = "\n",
       append = FALSE,
       col.names = !append,
       row.names = FALSE,
       qmethod = "escape"
  )
  </code></pre>
  
  <p>The output seems OK to me:</p>
  
  <pre><code>"x" "y"
  1   "Lorem ipsum dixit"
  2   "the \"brown\"
  fox"
  3   "a|b"
  </code></pre>
  
  <p>However when I read the dataset from file with</p>
  
  <pre><code>data.table::fread("testfile.tsv")
  </code></pre>
  
  <p>I get error:</p>
  
  <pre><code>Error in data.table::fread("x.gitignore.tsv") : 
  Expected sep (' ') but new line, 
    EOF (or other non printing character) ends field 0 
    when detecting types from point 0: fox"
  </code></pre>
  
  <p>I have tried to explicitly read stating the quoting character with:</p>
  
  <pre><code>data.table::fread("testfile.tsv", 
    sep "\t", header = T, na.strings = "NULL", quote = "\"")
  </code></pre>
  
  <p>but I still get the same error.</p>
  
  <p>I also tried to use read.delim but it skips the first row of data for some reason:</p>
  
  <pre><code>read.delim("testfile.tsv", header = T, sep = "\t", na.strings = "NULL")
  </code></pre>
  
  <p>So how can I write and read back such data frames using data.table and fwrite?</p>