Learn R Programming

mcstatsim (version 0.5.0)

mcpmap: Parallel Map Function using pbapply::pbmapply

Description

This function applies a given function over a list of parameters in parallel using multiple cores.

Usage

mcpmap(
  lists,
  func,
  num_cores = parallel::detectCores() - 1,
  show_progress = TRUE
)

Value

A list of results from applying the function over the parameters.

Arguments

lists

A list of lists containing the parameters for the function.

func

The function to be applied.

num_cores

The number of cores to use for parallel execution. Default is one less than the total number of available cores.

show_progress

Logical indicating whether to display the progress bar. Default is TRUE.

Details

The function ensures that all elements in the list have the same length and uses `pbapply::pbmapply` for parallel processing. It sets the number of cores based on the operating system and then applies the function in parallel.

Examples

Run this code
params <- list(a = 1:3, b = 4:6)
mcpmap(params, function(a, b) a + b, num_cores = 2)

Run the code above in your browser using DataLab