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 erro
You can also accomplish this kind of task with the purrr helper functions map and possibly. For exampel
purrr
map
possibly
library(purrr) map(dates2, possibly(testFunction, NA))
Here possibly will return NA (or whatever value you specified if an error occurs.