progress_lapply: 'lapply' with progress

View source: R/progress.R

progress_lapplyR Documentation

lapply with progress

Description

Drop-in replacement for lapply() that reports progress after each element: begins a progress node, ticks once per element, and ends the node. Nested calls produce a nested breadcrumb on the console (and parent_id-chained sink events). If fn throws, the node is ended with status = "error" before the condition propagates, so nested wrappers unwind cleanly.

Usage

progress_lapply(
  X,
  FUN,
  ...,
  label = "Processing",
  kind = "progress",
  parent_id = NULL,
  verbosity = NULL,
  package = NULL,
  output_type = NULL
)

Arguments

X

Vector or list: Elements to iterate over, as in lapply().

FUN

Function: Applied to each element of X. Named X/FUN to match lapply(), so arguments forwarded through ... (commonly x) never collide with the wrapper's own parameters.

...

Additional arguments passed to FUN.

label

Character: Display label for the progress node.

kind

Character: Node kind forwarded in the sink envelope.

parent_id

Character or NULL: Parent id for the sink envelope when this is the outermost active handle - see progress_begin().

verbosity

Integer or NULL: Overrides get_verbosity() when supplied. Gates only the console renderer, never sink events.

package

Character or NULL: Package name for verbosity override lookup.

output_type

Character or NULL: "ansi", "html", or "plain"; resolved via get_output_type() when NULL.

Details

message() and warning() conditions signalled by fn (or anything it calls) are intercepted by a calling handler that clears the status line before the text is printed, then lets normal handling proceed - so third-party verbose output lands on a clean line. Direct stdout writes (cat(), print()) cannot be intercepted; see progress_clear().

Value

List: Exactly what lapply(X, FUN, ...) returns.

Author(s)

EDG

See Also

Other progress: progress_begin(), progress_clear(), progress_end(), progress_update()

Examples

sqrts <- progress_lapply(
  1:4,
  sqrt,
  label = "Computing",
  output_type = "plain"
)

rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.