Skip to content

recovering from errors with lapply()

3 messages · Andrew Barr, Milan Bouchet-Valat

#
Le mardi 12 f?vrier 2013 ? 15:41 -0600, Andrew Barr a ?crit :
The problem happens before lapply() itself:
[1] "10"  "This is not a number"

A vector can only contain values of the same type, so 10 is converted to
a character value, and divideBy2("10") does not work. Try with:
lapply(list(10, "This is not a number"), divideBy2)

All that means that in real use cases, your tryCatch() solution should
work (I have not tested it). The bug is in your toy example.


Regards