[R] How to terminate R program if found any execution error
murdoch.duncan at gmail.com
Tue Sep 27 07:22:56 CEST 2011
On 11-09-27 12:20 AM, arunkumar1111 wrote:
> I want to terminate R process if there are any execution error.
> stop("Wrong Input Value")
> if c fails then it should terminate the process.
> Please can anyone help
Keep the try(a/b), but replace the conditional with
if (inherits(c, "try-error")) q("no")
See ?q if you want to set an error status to be returned, or do want to
save the workspace, etc.
(And do use inherits() rather than comparing to a particular entry:
your code will probably work in this example, but it's not the right way
to test the class of something, and some day "try-error" might not be
the first entry.)
More information about the R-help