Learn R Programming

purrrogress (version 0.1.1)

with_progress: Apply a function with progress bars.

Description

Apply a function with progress bars.

Usage

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

Run this code
# NOT RUN {
# with purrr functions
long_function <- function(x, how.long=0.05){
    Sys.sleep(how.long)
    x
}
# }
# NOT RUN {
purrr::walk(1:100, with_progress(long_function))
purrr::walk2(1:100, 0.01, with_progress(long_function))
# }
# NOT RUN {
# with dplyr::group_map
# }
# NOT RUN {
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)
}
# }
# NOT RUN {
# with standard apply functions
sapply(1:100, with_progress(long_function, type='txt'), 0.001)


# }

Run the code above in your browser using DataLab