Hello,
You can trap errors with ?try or ?tryCatch.
Example:
result <- vector(mode = "list", length = 5)
for(i in 1:5){
result[[i]] <- tryCatch(if(i == 3) stop("This is an error") else 2*i + 1,
error = function(e) e)
}
result
for(i in seq_along(result)) {
err <- inherits(result[[i]], "error")
print(err)
}
Hope this helps,
Rui Barradas
Às 20:55 de 27/02/2019, Bernard Comcast escreveu:
What is the recommended way to trap errors in R? My main need is to be able to
trap an error and then skip a section of code if an error has occurred. In VB
for Excel I used the “On Error goto .....” construct to do this.
Bernard
Sent from my iPhone so please excuse the spelling!"
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.