Package 'aurrera'

Title: Wrap an Interable in a Progress Bar
Description: Allows a simple creation of progress bars by wrapping the iterated object in 'pb()'.
Authors: Laura Bakala [cre, aut, cph]
Maintainer: Laura Bakala <[email protected]>
License: GPL (>= 3)
Version: 0.1.0
Built: 2025-02-24 06:19:19 UTC
Source: https://github.com/turtletopia/aurrera

Help Index


Add a progress bar to an iterable

Description

Makes the object spawn a progress bar in response to indexing with [[ operator. Intended to be used with most iterators in R, e.g.: base::lapply() and some of its cousins, base::Reduce(), plyr::llply(), purrr::map(), foreach::foreach()...

Usage

pb(object, ...)

## Default S3 method:
pb(object, ...)

## S3 method for class 'aurrera_iter'
pb(object, ...)

Arguments

object

ANY
An iterable that should spawn a progress bar.

...

ANY
Additional parameters to be used in the future (e.g. progress bar customization).

Value

The original object with aurrera_iter class prepended that handles progress bar display in response to indexing.

Examples

result <- lapply(pb(6:20), gmp::factorize)

Reduce(`+`, pb(sample(1e5, 1e4)))

# Progress bar won't display when iterating with `for` loop
v <- character()
for (letter in pb(letters[1:5])) {
  v <- c(letter, v)
}
v

# On the other hand, manual indexing works properly
x <- pb(letters[1:5])
for (i in seq_along(x)) {
  # Just be careful with printing inside a progress bar
  print(x[[i]])
}