To perform tasks in the union function, you need to include additional information in the result object returned by the body of the foreach loop. In this case, it will be an error flag and a value of i . There are many ways to do this, but here is an example:
comb <- function(results, x) { i <- x$i result <- x$result if (x$error) { cat(sprintf('master computing failed task %d\n', i))
I will be tempted to solve this problem by repeating a parallel loop until all tasks are calculated:
x <- rnorm(100) results <- lapply(x, function(i) simpleError(''))
Note that this solution uses the .errorhandling parameter, which is very useful if errors can occur. For more information about this option, see the foreach man page.
source share