Problems with try() inside foreach() in R
问题 I am trying to use the try() function to deal with errors that are occurring in my parallelised for loop: results <- foreach (i = 1:2, .errorhandling = 'remove') %dopar% { res <- try(myfun(i), TRUE) } with myfun <- function(i){ if (i==1) return(rnorm(1)) else stop('error') } I get the following error message Error in checkForRemoteErrors(val) : one node produced an error: Error in myfun(i) : error How can I get the foreach "loop" to ignore the error message (or at least deal with it a little