Displaying 2 results from an estimated 2 matches for "lapply_with_error".
2020 Oct 08
2
exiting mclapply early on error
Hey folks,
Is there any way to exit an mclapply early on error?
For example, in the following mclapply loop, I have to wait for all the processes to finish before the error is returned.
```
mclapply(X = 1:12, FUN = function(x) {Sys.sleep(0.1); if(x == 4) stop()}, mc.cores = 4, mc.preschedule = F)
```
When there are many calculations in FUN, it takes a long time before the error is returned.
2020 Oct 09
0
exiting mclapply early on error
...sses alive as long as they can. If the computation time is long I
would not want to lose everything.
lapply..8 <- function(X,FUN,...){
max..cores <- as.numeric(system("grep ^processor /proc/cpuinfo 2>/dev/null | wc -l",TRUE))
mclapply(X,FUN,mc.cores=min(max..cores,8))
}
lapply_with_error..8 <- function(X,FUN,...) {
lapply..8(X, function(x, ...) tryCatch(FUN(x, ...),
error=function(e){
print(e)
e}
))
}
res <-...