[R] class of 'try' if error is raised

Hans W Borchers hwborcher@ @end|ng |rom gm@||@com
Sun Dec 15 15:20:41 CET 2019


I have been informed by CRAN administrators that the development
version of R issues warnings for my package(s). Some are easy to mend
(such as Internet links not working anymore), but this one I don't
know how to avoid:

    Error in if (class(e) == "try-error") { : the condition has length > 1

I understand that `class` can return more than one value. But what
would be the appropriate way to catch an error in a construct like
this:

    e <- try(b <- solve(a), silent=TRUE)
    if (class(e) == "try-error") {
        # ... do something
    }

Should I instead compare the class with "matrix" or "array" (or
both)?. That is, in each case check with a correct result class
instead of an error?

Thanks, HW



More information about the R-help mailing list