Created
August 18, 2023 20:08
-
-
Save MVesuviusC/7ca8eab00cabd923f47ab0eb08b78add to your computer and use it in GitHub Desktop.
Deal with try-errors in mclapply and get warning message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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