Skip to content
Prev 305814 / 398506 Next

Trap an error from a function

On 12-09-18 8:10 PM, John Sorkin wrote:
You can wrap the call in try().  Then check whether the result inherits 
from try-error, e.g.

res <- try( ... )
if (inherits(res, "try-error")) { do something to handle the error }
else { proceed as you would with no error }

In the example you gave, the problem is that even a sample size of 2 
gives more than 0.8 power.  The function should probably check for that 
case, but it doesn't.

Duncan Murdoch