with_progress: Apply a function with progress bars.

Description Usage Arguments Examples

View source: R/with_progress.R

Description

Apply a function with progress bars.

Usage

1
with_progress(fun, total, ...)

Arguments

fun

The function to be apply

total

The total number of elements to be mapped. If omitted an attempt will be made to infer the correct number.

...

Arguments passed on to progress_bar

total

the total number of elements

title

the title of the progress bar

type

the type of progress bar to create as a string, or an R6ClassGenerator object for a class that inherits from the "R6 Progress Base Class".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# with purrr functions
long_function <- function(x, how.long=0.05){
    Sys.sleep(how.long)
    x
}

purrr::walk(1:100, with_progress(long_function))
purrr::walk2(1:100, 0.01, with_progress(long_function))


# with dplyr::group_map

if(require(dplyr)){
group_function <- function(x, y, how.long=0.05){
    Sys.sleep(how.long)
    x
}
group_map( group_by(mtcars, cyl, gear)
         , with_progress(group_function, type='line')
         , how.long=1/3)
group_walk( group_by_all(mtcars)
          , with_progress(group_function, type='box')
          , how.long=1)
}

# with standard apply functions
sapply(1:100, with_progress(long_function, type='txt'), 0.001)

purrrogress documentation built on July 23, 2019, 1:04 a.m.