title: How to tell lapply to ignore an error and process the next thing in the list?
body: <p>I have an example function below that reads in a date as a string and returns it as a date object.  If it reads a string that it cannot convert to a date, it returns an error.</p>
  
  <pre><code>testFunction &lt;- function (date_in) {
      return(as.Date(date_in))
      }
  
  testFunction("2010-04-06")  # this works fine
  testFunction("foo")  # this returns an error
  </code></pre>
  
  <p>Now, I want to use lapply and apply this function over a list of dates:</p>
  
  <pre><code>dates1 = c("2010-04-06", "2010-04-07", "2010-04-08")
  lapply(dates1, testFunction)  # this works fine
  </code></pre>
  
  <p>But if I want to apply the function over a list when one string in the middle of two good dates returns an error, what is the best way to deal with this?   </p>
  
  <pre><code>dates2 = c("2010-04-06", "foo", "2010-04-08")
  lapply(dates2, testFunction)
  </code></pre>
  
  <p>I presume that I want a try catch in there, but is there a way to catch the error for the "foo" string whilst asking lapply to continue and read the third date?</p>