Re: [R] continue a for() when occurs errors

From: Ted Harding <>
Date: Thu, 20 Dec 2007 10:00:34 -0000 (GMT)

On 20-Dec-07 08:24:40, Milton Cezar Ribeiro wrote:
> Dear all,
> I am simulating some regressions in a for() looping and sometimes
> occours some error and the R stop my batch processing. I would like do
> save the step where the error happned and continue my for() looping.
> Is there a way to do that?
> Thanks In Advance.
> Miltinho

try() is the simple way: see ?try for some basic details. See also ?tryCatch


  if(class(temp<-try(log("a")))=="try-error"){     print("Goodbye")
  } else {print("Hello:");print(temp)}
##Error in log(x) : Non-numeric argument to mathematical function ##[1] "Goodbye"

  if(class(temp<-try(log(10)))=="try-error"){     print("Goodbye")
  } else {print("Hello:");print(temp)}
##[1] "Hello:"
##[1] 2.302585

Hoping this helps,

E-Mail: (Ted Harding) <> Fax-to-email: +44 (0)870 094 0861
Date: 20-Dec-07                                       Time: 10:00:30
------------------------------ XFMail ------------------------------

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 20 Dec 2007 - 10:05:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 20 Dec 2007 - 10:30:19 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.