On 11-09-27 12:20 AM, arunkumar1111 wrote:
Hi

   I want to terminate R process if there are any execution error.

a="a"
b=10
c=try(a/b)

if(class(c)[1]=="try-error")
{
        stop("Wrong Input Value")
}

d=c*c



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.)

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to