[R] Automatic re-looping after error

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Mon Oct 13 11:50:16 CEST 2003


On 13-Oct-03 Martin Maechler wrote:
> slightly more recommendable code is
> 
>    result <- try(myfun(...))
>    if(inherits(result, "try-error")) next 
> 
> 
> - using  inherits(obj, cls) is more robust than 
>   class(obj) == cls because it also works when  `obj' has more
>   than one class (e.g. a `glm' object) or when `obj' has no
>   class {i.e. when `methods' is not attached or in older R versions}.

Thanks! (I had been worried about exactly this kind of issue, though in
fact it worked in the case I had.)

> - no trailing ";"

... Old C (and awk) habits die hard ...

Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 13-Oct-03                                       Time: 10:50:16
------------------------------ XFMail ------------------------------




More information about the R-help mailing list