Skip to content

error options

2 messages · Paul Murtaugh, Bert Gunter

#
Hi,

I'm running simulations that include a function that occasionally fails
because of an unpredictable singularity in a matrix that it tries to invert.
I'd like to have the function return 'NA' when that happens, so that the
simulations can continue.  I've tried things like:

    test <- function() {
    options(error=return(NA))
    x <- solve(0)
    return(x)
    }

which does return 'NA'.  But it returns 'NA' whether or not there's an
error in the function:

    test <- function() {
    options(error=return(NA))
    x <- 0
    return(x)
    }

    test()
    [1] NA

What am I missing here?

Thanks in advance
-Paul
#
Below.

-- Bert

On Wed, Dec 28, 2011 at 11:35 AM, Paul Murtaugh
<murtaugh at science.oregonstate.edu> wrote:
error trapping.
?try   ##or
?tryCatch

-- Bert