title: How to check if CSV file has a comma or a semicolon as separator?
body: <p>I have to read in a lot of CSV files automatically. Some have a comma as a delimiter, then I use the command <code>read.csv()</code>.</p>
  <p>Some have a semicolon as a delimiter, then I use <code>read.csv2()</code>.</p>
  <p>I want to write a piece of code that recognizes if the CSV file has a comma or a semicolon as a a delimiter (before I read it) so that I don´t have to change the code every time.</p>
  <p>My approach would be something like this:</p>
  <pre><code>try to read.csv(&quot;xyz&quot;)
  if error 
  read.csv2(&quot;xyz&quot;)
  </code></pre>
  <p>Is something like that possible? Has somebody done this before?
  How can I check if there was an error without actually seeing it?</p>