Parallelize a function
Arguments
- x
A vector or list to apply over.
- fun
The function to be applied to each element.
- cores
The number of cores to use for parallelization with
foreach
. Default is1
.- export_fun
The functions to export the function to workers.
- verbose
Logical value, default is
TRUE
. Whether to print progress messages.
Examples
parallelize_fun(1:3, function(x) x^2)
#> ℹ [2025-06-17 13:26:33] Using 1 core
#> ℹ [2025-06-17 13:26:33] Elapsed 0.00 sec
#> $`1`
#> [1] 1
#>
#> $`2`
#> [1] 4
#>
#> $`3`
#> [1] 9
#>
parallelize_fun(list(1, 2, 3), function(x) x^2)
#> ℹ [2025-06-17 13:26:33] Using 1 core
#> ℹ [2025-06-17 13:26:33] Elapsed 0.00 sec
#> $`1`
#> [1] 1
#>
#> $`2`
#> [1] 4
#>
#> $`3`
#> [1] 9
#>