Description Usage Arguments Examples
View source: R/with_progress.R
Apply a function with progress bars.
1 | with_progress(fun, total, ...)
|
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
|
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.