Message-ID: <XFMail.071220100034.Ted.Harding@manchester.ac.uk>
Date: 2007-12-20T10:00:34Z
From: (Ted Harding)
Subject: continue a for() when occurs errors
In-Reply-To: <974143.33371.qm@web56005.mail.re3.yahoo.com>
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
Example:
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,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 20-Dec-07 Time: 10:00:30
------------------------------ XFMail ------------------------------