title: How to detect comma vs semicolon separation in a file before reading it?
body: <p>I'm using readr and purrr to map reduce through a set of filenames, read the files and combine them into one single tibble.</p>
  <p>The data comes from an external partner. Most files are semicolon separated and can be read using read_csv2, but some comma separated files are spread into the set of files.</p>
  <p>I'm wondering what could be the simplest way to quickly detect if the file is a comma or semicolon separated file before reading it, so I could either apply read_csv or read_csv2 ?</p>
  <p>My code is as below, and uses purrr map reduce functions, as well as a formula for reading each file and transforming content before binding the results into a single dataset.</p>
  <pre><code>ndr_path &lt;- &quot;C:/Data&quot;
  
  file_names &lt;- file.path(ndr_path, list.files(ndr_path, &quot;01.b forecasts 202[1-9][0-9]{4,4}\\.csv&quot;))
  
  data &lt;- file_names[1] %&gt;%
    map(~ {
      read_csv2(.x) %&gt;%
        select(Product, &quot;Product Description&quot;, Date, &quot;NDR&quot;) %&gt;%
        mutate(VMIDate = as.Date(gsub(&quot;^.*(\\d{8})\\.csv$&quot;, &quot;\\1&quot;, .x), format=&quot;%Y%m%d&quot;)) %&gt;%
        mutate(NDR = as.numeric(NDR))
    }) %&gt;%
    reduce(rbind)
  </code></pre>
  <p>Thanks!</p>