par_sapply {berryFunctions}R Documentation

cross-platform parallel processing with progbar

Description

Call pbapply::pbsapply with nc default at number of cores available. Also, this works on Windows directly. Note this throws an error on unix systems, unlike parallel::mclapply

Usage

par_sapply(
  X,
  FUN,
  nc = NULL,
  pb = TRUE,
  simplify = TRUE,
  export_objects = NULL,
  ...
)

Arguments

X

vector / list of values

FUN

function to be executed with each element of X.

nc

Integer: number of cores to be used in parallel. DEFAULT: NULL (available cores)

pb

Show progress bar with remaining time and at the end runtime? DEFAULT: TRUE

simplify

Simplify output to vector/matrix if possible? Note that simplify="array" is not implemented here. DEFAULT: TRUE

export_objects

For windows: Objects needed in FUN. DEFAULT: NULL

...

Further arguments passed to FUN or pbapply::pbsapply

Value

vector/matrix, list if simplify=FALSE

Author(s)

Berry Boessenkool, berry-b@gmx.de, Apr 2021

See Also

pbapply::pbsapply, sapply, parallelCode

Examples

## Not run:  # Suppressed on CRAN checks as this is time-consuming
fun <- function(x) mean(rnorm(1e7))
pbapply::pbsapply(1:20, fun)
       par_sapply(1:20, fun)
          #sapply(1:20, fun)

## End(Not run)
inp_chr_named <- list(first=1, second=2, third="3", fourth=4, fifth="5")
inp_num_named <- lapply(inp_chr_named, as.numeric)
inp_chr_none <- unname(inp_chr_named)
inp_num_none <- unname(inp_num_named)
if(FALSE){#intentional errors, don't run
par_sapply(inp_chr_named, log) # fails with name(s)
par_sapply(inp_num_named, log) # works, has names
par_sapply(inp_chr_none, log) # fails with index number (s)
par_sapply(inp_num_none, log) # no names, like in sapply
}


[Package berryFunctions version 1.22.0 Index]