[R] parallel error message extraction (in mclapply)?

Neal H. Walfield
Sat, 29 Dec 2012 10:26:57 -0000

Hi, Ivo,

At Fri, 28 Dec 2012 16:34:03 -0800,
ivo welch wrote:
> so, it isn't obvious to me how I get to the try-error object
> list, or how to find out what triggered the abort.

A try object is an object that captures the execution context at the
time of an error.  Consider the following code:

  > library(multicore)
  > result = mclapply(1:10, function (i) { if (i == 4) foo() else i })
  Warning message:
  In mclapply(1:10, function(i) { :
    scheduled core 4 encountered error in user code, all values of the job will
be affected

To investigate the error, we can use the try object that has been
saved in position 4:

  > print(result[[4]])
  [1] "Error in FUN(4L[[1L]], ...) : could not find function
\"foo\"\n"
  attr(,"class")
  [1] "try-error"
  attr(,"condition")
  <simpleError in FUN(4L[[1L]], ...): could not find function "foo"
  > traceback(result[[4]])
  1: Error in FUN(4L[[1L]], ...) : could not find function "foo"

Neal