I have a parallel process that looks like this:
library(foreach)
library(doSNOW)
cl = makeCluster(parallel::detectCores() - 1, type = "SOCK", outfile = "out.txt")
registerDoSNOW(cl)
l = foreach(i = 1:100) %dopar% {
res = withCallingHandlers(
read.csv("somefilethatdoesntexist.csv"), error = function(e) e)
if(inherits(res, "error")) res = NULL
res
}
My expectation is that even if there is an error in "expression" the loop should continue, but it exits with an error and the resulting "l" variable is not created.
This seems to happen especially related to missing files. But if I'm wrapping it in a tryCatch and handling appropriately within "expression" how can it error out?
Maybe this (adapted from here):