fmap | R Documentation |
Applies a function '.f' to each element of '.x', with optional parallel processing and progress bar support.
fmap(.x, .f, ncores = NULL, pb = FALSE, ...)
.x |
A list or atomic vector of elements to iterate over. |
.f |
A function to apply to each element of '.x'. Can be a function or a string naming a function. |
ncores |
Integer. Number of CPU cores to use for parallel processing. Default is 'NULL' (sequential). |
pb |
Logical. Whether to show a progress bar. Default is 'FALSE'. |
... |
Additional arguments passed to '.f'. |
A list of results, one for each element of '.x'.
slow_fn <- function(x) { Sys.sleep(0.01); x^2 }
x <- 1:100
# Basic usage
fmap(x, slow_fn)
# With progress bar
fmap(x, slow_fn, pb = TRUE)
# With parallel execution (non-Windows)
if (.Platform$OS.type != "windows") {
fmap(x, slow_fn, ncores = 2, pb = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.