Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch an error/exception in R? [duplicate]

Tags:

r

Possible Duplicate:
Exception handling in R

Does anyone have idea on how to catch an error or an exception in R?

like image 508
Shruti Avatar asked Oct 28 '10 20:10

Shruti


2 Answers

Like Joshua said: use tryCatch. Include an error argument, which should be a function accepting one parameter (the error, typically called e).

tryCatch(
  stop("you threw an error"), 
  error = function(e) 
  {
    print(e$message) # or whatever error handling code you want
  }
)
like image 53
Richie Cotton Avatar answered Oct 24 '22 12:10

Richie Cotton


It really depends on what you mean by "catch". Look at tryCatch and withCallingHandlers.

like image 36
Joshua Ulrich Avatar answered Oct 24 '22 13:10

Joshua Ulrich