Skip to content

Commit

Permalink
Merge pull request #1734 from mkuhn/master
Browse files Browse the repository at this point in the history
update the progress bar only 20 times per second
  • Loading branch information
hadley committed Mar 23, 2016
2 parents 06b1b20 + 03c8c89 commit a7528c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# dplyr 0.4.3.9000

* The progress bar in `do()` is now updated at most 20 times per second, avoiding uneccessary redraws (#1734, @mkuhn)

* joins allows extra attributes if they are identical (#1636)

* `summarise()` correctly coerces factors with different levels (#1678)
Expand Down
8 changes: 6 additions & 2 deletions R/progress.R
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 a7528c2

Please sign in to comment.