floop | R Documentation |
'floop()' applies a function '.f' to each element of '.x', optionally in parallel, and with an optional progress bar. Unlike 'fwalk()', it can return results or be used purely for side effects (like a for-loop).
floop(.x, .f, ncores = 1, pb = FALSE, .capture = TRUE, ...)
.x |
A vector or list of elements to iterate over. |
.f |
A function to apply to each element of '.x'. |
ncores |
Integer. Number of cores to use. Default is 1 (sequential). |
pb |
Logical. Show a progress bar? Default is 'FALSE'. |
.capture |
Logical. Should results of '.f' be captured and returned? If 'FALSE', acts like a side-effect loop. |
... |
Additional arguments passed to '.f'. |
A list of results if '.capture = TRUE', otherwise returns '.x' invisibly.
# Functional loop that collects output
floop(1:3, function(i) i^2)
# Side-effect only loop (like for-loop with cat)
floop(1:5, function(i) cat(" Processing", i, "\n"), pb = TRUE, .capture = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.