Problems with try() inside foreach() in R

后端 未结 2 1372
不知归路
不知归路 2021-02-07 11:18

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, .errorhand         


        
2条回答
  •  猫巷女王i
    2021-02-07 11:36

    You can use tryCatch and deal with the error appropriately. Here the error is ignored (returning NULL)

    results <- foreach (i = 1:2) %dopar% {
        res <- tryCatch({
            myfun(i)
        }, error=function(e) NULL)
    }
    

    or just using the builtin .errorhandling='remove' as you have, without the try should remove the errors already.

提交回复
热议问题