with_progress: Execute Expression with Progress Reporting

View source: R/progress_utils.R

with_progressR Documentation

Execute Expression with Progress Reporting

Description

Wrapper function that executes an expression with optional progress reporting. Integrates with the progressr package when available.

Usage

with_progress(expr, name = "Processing", enable = TRUE)

Arguments

expr

Expression to evaluate

name

Character string specifying the name of the operation (default: "Processing")

enable

Logical indicating whether to enable progress reporting (default: TRUE). If FALSE or if progressr is not available, the expression is executed without progress reporting.

Details

This function provides a consistent interface for progress reporting across riemtan. Progress handlers can be configured using progressr::handlers().

When enable = TRUE and progressr is installed, users can see progress by calling:

progressr::handlers("progress")  # or "txtprogressbar", "cli", etc.

Value

The result of evaluating expr.

See Also

progressr::with_progress(), progressr::progressor()

Examples

## Not run: 
# Enable progress reporting
progressr::handlers("progress")

# Use within a function
result <- with_progress({
  p <- progressr::progressor(steps = 10)
  lapply(1:10, function(i) {
    Sys.sleep(0.1)
    p()  # Signal progress
    i^2
  })
}, name = "Computing squares")

## End(Not run)


riemtan documentation built on Nov. 11, 2025, 1:06 a.m.