Displaying 1 result from an estimated 1 matches for "divideby2".
Did you mean:
divide_by_2
2013 Feb 12
1
recovering from errors with lapply()
Hi all,
I am searching for a way to recover results from lapply() when one or more
values returns an error. I have a written a function that uses tryCatch()
to recover from errors. Here is a very simple example of such a function.
divideBy2<-function(X){
result<-tryCatch(X/2, error = function(e) "An Error Occurred")
return(result)
}
This function appears to work as I expect both in cases where an error
occurs and where no error occurs.
divideBy2(10)
# [1] 5
divideBy2("This is not a number")
# [1] "...