On Tue, Nov 16, 2010 at 10:58 AM, Aleksey Naumov <anau...@gmail.com> wrote: > Hi R experts, > > I am looking for a simple error handling approach, whereby I could stop > function execution with a customized error message. For example: > > for (i in 1:10) { > if (i == 5) > # I'd like to be able to stop right here with an error message I have > complete control over > } > > The problem with stop() is that I cannot control completely what gets > printed to the terminal, even with stop(call.=FALSE) there is the "Error:" > string. I've worked through examples (whatever few there are) for try() and > tryCatch() and I still cannot understand how to do this. If I supply my own > error handler function with tryCatch(..., error=function(e) ...) I can > control the error message, but the loop continues on to i=6, etc. > > So I am struggling with error handling in R... It' seems its a lot simpler > and more consistent e.g. in Python. > > Any help would be greatly appreciated! >
There was a long thread on this a couple of years ago. You might want to look at this response regarding callCC and also the other responses: http://tolstoy.newcastle.edu.au/R/e5/help/08/11/6967.html -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ 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.