title: Conditionally read a csv with a given separator and if that separator does not work read.csv using a different separator
body: <p>I am trying to download some CSV's from some links. Most of the CSV's are separated by <code>;</code> however, one or two are separated by <code>,</code>. Running the following code:</p>
  <pre><code>foo &lt;- function(csvURL){
    downloadedCSV = read.csv(csvURL, stringsAsFactors = FALSE, fileEncoding = &quot;latin1&quot;, sep = &quot;;&quot;)
    return(downloadedCSV)
  }
  
  dat &lt;- purrr::map(links, foo)
  </code></pre>
  <p>Gives me a list of 3 <code>data.frame</code>'s. Two of them have 2 columns (correctly read in by the <code>;</code> separator) and one of them has 1 column (incorrectly read in by the <code>;</code> separator) because this file uses the <code>,</code> separator.</p>
  <p>How can I incorporate into the function something like if the number of columns == 1 re-read the data but this time using <code>,</code> instead of <code>;</code>? I tried passing <code>sep = &quot;;|,&quot;</code> to the <code>read.csv</code> function but had no luck.</p>
  <p>Links data:</p>
  <pre><code>links &lt;- c(&quot;https://dadesobertes.gva.es/dataset/686fc564-7f2a-4f22-ab4e-0fa104453d47/resource/bebd28d6-0de6-4536-b522-d013301ffd9d/download/covid-19-total-acumulado-de-casos-confirmados-pcr-altas-epidemiologicas-personas-fallecidas-y-da.csv&quot;, 
  &quot;https://dadesobertes.gva.es/dataset/686fc564-7f2a-4f22-ab4e-0fa104453d47/resource/b4b4d90b-08cf-49e4-bef1-5608311ce78a/download/covid-19-total-acumulado-de-casos-confirmados-pcr-altas-epidemiologicas-personas-fallecidas-y-da.csv&quot;, 
  &quot;https://dadesobertes.gva.es/dataset/686fc564-7f2a-4f22-ab4e-0fa104453d47/resource/62990e05-9530-4f2f-ac41-3fad722b8515/download/covid-19-total-acumulado-de-casos-confirmados-pcr-altas-epidemiologicas-personas-fallecidas-y-da.csv&quot;
  )
  </code></pre>