## -----------------------------------------------------------------------
## Catch errors:
## -----------------------------------------------------------------------
## By default 'catch.errors' is TRUE in BiocParallelParam objects.
SnowParam(workers = 2)
## If 'catch.errors' is FALSE an ill-fated bplapply() simply stops
## displaying the error message.
snowp <- SnowParam(workers = 2, catch.errors = FALSE)
## Not run:
# > res <- bplapply(list(1, "two", 3), sqrt, BPPARAM = snowp)
# Error in checkForRemoteErrors(val) :
# one node produced an error: non-numeric argument to mathematical function
# ## End(Not run)
## When 'catch.errors' is TRUE the same call provides traceback
## information (truncated here) and suggests use of bplasterror() and
## bpresume().
snowp <- SnowParam(workers = 2)
## Not run:
# > res <- bplapply(list(1, "two", 3), sqrt, BPPARAM = snowp)
# Error: 1 errors; first error:
# Error in FUN(...): non-numeric argument to mathematical function
#
# For more information, use bplasterror(). To resume calculation, re-call
# the function and set the argument 'BPRESUME' to TRUE or wrap the
# previous call in bpresume().
#
# First traceback:
# 19: parallel:::.slaveRSOCK()
# 18: slaveLoop(makeSOCKmaster(master, port, timeout, useXDR))
# ...
# ## End(Not run)
## bplasterror() reports the number of successful results and error message.
## Not run:
# > bplasterror()
# 2 / 3 partial results stored. First 1 error messages:
# [2]: Error in FUN(...): non-numeric argument to mathematical function
# ## End(Not run)
## -----------------------------------------------------------------------
## Resume calculations:
## -----------------------------------------------------------------------
## The 'resume' mechanism attempts to re-run the data element that failed.
## In our example the character "two" list element will never succeed. In
## the runs below we replace the character with a numeric and compute the
## result.
## There are two methods for resuming a suspended calculation, one
## approach is to wrap the original call in bpresume().
## Not run:
# > bpresume(res <- bplapply(list(1, 2, 3), sqrt, BPPARAM = snowp))
# Resuming previous calculation...
# > res
# [[1]]
# [1] 1
#
# [[2]]
# [1] 1.414214
#
# [[3]]
# [1] 1.732051
# ## End(Not run)
## An equivalent approach is to set 'BPRESUME = TRUE' in bplapply().
## Not run:
# res <- bplapply(list(1, 2, 3), sqrt, BPPARAM = snowp, BPRESUME = TRUE)
# ## End(Not run)
Run the code above in your browser using DataLab