Skip to content

Commit

Permalink
update the progress bar only 20 times per second
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuhn committed Mar 23, 2016
1 parent 06b1b20 commit cf1e842
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/progress.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Progress <- R6::R6Class("Progress",
stopped = FALSE,
stop_time = NULL,
min_time = NULL,
last_update = NULL,

initialize = function(n, min_time = 0, ...) {
self$n <- n
Expand All @@ -57,7 +58,7 @@ Progress <- R6::R6Class("Progress",
begin = function() {
"Initialise timer. Call this before beginning timing."
self$i <- 0
self$init_time <- now()
self$last_update <- self$init_time <- now()
self$stopped <- FALSE
self
},
Expand Down Expand Up @@ -95,9 +96,12 @@ Progress <- R6::R6Class("Progress",
!is.null(getOption("knitr.in.progress"))) { # dplyr used within knitr document
return(invisible(self))
}
if (now() - self$init_time < self$min_time) {

now_ <- now()
if (now_ - self$init_time < self$min_time || now_ - self$last_update < 0.05) {
return(invisible(self))
}
self$last_update <- now_

if (self$stopped) {
overall <- show_time(self$stop_time - self$init_time)
Expand Down

0 comments on commit cf1e842

Please sign in to comment.