## We don't run the examples on CRAN, because they takes >10s
## altogether. Unfortunately it is hard to create a set of
## meaningful progress bar examples that also run quickly.
if (FALSE) {
## Basic
pb <- progress_bar$new(total = 100)
for (i in 1:100) {
pb$tick()
Sys.sleep(1 / 100)
}
## ETA
pb <- progress_bar$new(
format = " downloading [:bar] :percent eta: :eta",
total = 100, clear = FALSE, width= 60)
for (i in 1:100) {
pb$tick()
Sys.sleep(1 / 100)
}
## Elapsed time
pb <- progress_bar$new(
format = " downloading [:bar] :percent in :elapsed",
total = 100, clear = FALSE, width= 60)
for (i in 1:100) {
pb$tick()
Sys.sleep(1 / 100)
}
## Spinner
pb <- progress_bar$new(
format = "(:spin) [:bar] :percent",
total = 30, clear = FALSE, width = 60)
for (i in 1:30) {
pb$tick()
Sys.sleep(3 / 100)
}
## Custom tokens
pb <- progress_bar$new(
format = " downloading :what [:bar] :percent eta: :eta",
clear = FALSE, total = 200, width = 60)
f <- function() {
for (i in 1:100) {
pb$tick(tokens = list(what = "foo "))
Sys.sleep(2 / 100)
}
for (i in 1:100) {
pb$tick(tokens = list(what = "foobar"))
Sys.sleep(2 / 100)
}
}
f()
## Download (or other) rates
pb <- progress_bar$new(
format = " downloading foobar at :rate, got :bytes in :elapsed",
clear = FALSE, total = NA, width = 60)
f <- function() {
for (i in 1:100) {
pb$tick(sample(1:100 * 1000, 1))
Sys.sleep(2/100)
}
pb$tick(1e7)
invisible()
}
f()
pb <- progress_bar$new(
format = " got :current rows at :tick_rate/sec",
clear = FALSE, total = NA, width = 60)
f <- function() {
for (i in 1:100) {
pb$tick(sample(1:100, 1))
Sys.sleep(2/100)
}
pb$terminate()
invisible()
}
f()
}
Run the code above in your browser using DataLab