[R] exiting mclapply early on error

Giovanni Righi gr|gh| @end|ng |rom ug@@edu
Thu Oct 8 22:52:02 CEST 2020


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. It would be nice if there were an option to exit (all child processes) early on error. Is there any way to do this?

Thanks,
Giovanni Righi



More information about the R-help mailing list