How to tell lapply to ignore an error and process the next thing in the list?

后端 未结 4 1475
失恋的感觉
失恋的感觉 2020-11-27 13:41

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

4条回答
  •  难免孤独
    2020-11-27 14:28

    You can also accomplish this kind of task with the purrr helper functions map and possibly. For exampel

    library(purrr)
    map(dates2, possibly(testFunction, NA))
    

    Here possibly will return NA (or whatever value you specified if an error occurs.

提交回复
热议问题