parallelize_fun(1:3, function(x) {
Sys.sleep(0.2)
x^2
})
parallelize_fun(list(1, 2, 3), function(x) {
Sys.sleep(0.2)
x^2
}, cores = 2)
# Examples with error handling
parallelize_fun(1:5, function(x) {
if (x == 3) stop("Error on element 3")
x^2
}, clean_result = FALSE)
parallelize_fun(1:5, function(x) {
if (x == 3) stop("Error on element 3")
x^2
}, clean_result = TRUE)
# Control error printing
parallelize_fun(1:5, function(x) {
if (x == 2) stop("Error on element 3")
if (x == 4) stop("Error on element 4")
x^2
})
parallelize_fun(1:5, function(x) {
if (x == 3) stop("Error on element 3")
x^2
}, throw_error = FALSE)
Run the code above in your browser using DataLab