title: what is a binary file and when to use writeBin() in R
body: <p>I am having trouble understanding the nature of binary format and its usefulness in R, so I experimented a little:</p>
  
  <p>In R:</p>
  
  <pre><code>y1 = rbind(c('a', 'b'), c('c', 'd'))
  write.table(y1, 'f1', quote=F, col.names=F, row.names=F)
  conn = file('f2', 'wb')
  writeBin('a b\nc d\n', conn)
  close(conn)
  </code></pre>
  
  <p>In bash:</p>
  
  <pre><code>cat f1
  # a b
  # c d
  cat f2
  # a b
  # c d
  </code></pre>
  
  <p>These look exactly the same, but if I diff them:</p>
  
  <pre><code>diff f1 f2
  # Binary files f1 and f2 differ
  </code></pre>
  
  <p>diff didn't tell me what the difference is though.</p>
  
  <p>So back to the topic, what is a binary file (since everything is binary after all on a PC), and in what circumstances should I use it in R?</p>