floop: Functional loop with optional parallelism and progress bar

View source: R/floop.R

floopR Documentation

Functional loop with optional parallelism and progress bar

Description

'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).

Usage

floop(.x, .f, ncores = 1, pb = FALSE, .capture = TRUE, ...)

Arguments

.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'.

Value

A list of results if '.capture = TRUE', otherwise returns '.x' invisibly.

Examples

# 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)



functionals documentation built on Aug. 8, 2025, 7:32 p.m.