Skip to content

Instantly share code, notes, and snippets.

@MVesuviusC
Created August 18, 2023 20:08
Show Gist options
  • Save MVesuviusC/7ca8eab00cabd923f47ab0eb08b78add to your computer and use it in GitHub Desktop.
Save MVesuviusC/7ca8eab00cabd923f47ab0eb08b78add to your computer and use it in GitHub Desktop.
Deal with try-errors in mclapply and get warning message
test <- parallel::mclapply(as.list(0:5), function(x) {
print(x)
if (x == 0) {
stop("something didn't work for ", x)
}
return(1)
})
if (any(lapply(test, function(x) class(x) == "try-error") |> unlist())) {
stop("something didn't work")
}
test2 <- lapply(test,
function(x) if(class(x) == "try-error") { warning(x[[1]]) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment