Utility to use different implementations of lapply.

util_lapply(FUN, args, par = TRUE, ncores = NULL)

Arguments

FUN

Function to apply.

args

Named list. Arguments to pass to FUN. The first item (args[[1]]) should be first argument of FUN. This corresponds to the argument X in mclapply, parLapply or lapply.

par

Logical. If TRUE, use multiple cores.

ncores

Integer. Number of cores to use if par = TRUE. If unspecified, defaults to detectCores() - 1.

Examples

util_lapply( FUN = rnorm, args = list( n = rep(x = 5, times = 5), mean = 100, sd = 15 ), par = FALSE )
#> [[1]] #> [1] 78.99935 103.82976 63.44105 99.91643 109.32329 #> #> [[2]] #> [1] 117.22617 72.67274 96.29012 96.33701 95.75942 #> #> [[3]] #> [1] 91.69451 109.43473 130.97537 75.53516 107.68640 #> #> [[4]] #> [1] 72.05483 92.16981 99.21097 108.14495 86.28888 #> #> [[5]] #> [1] 107.02232 105.44427 80.43185 111.06664 128.32757 #>