R/progress_display.R

Defines functions get_progress_display progress_display_reset progress_now duckdb_progress_display

# Handbook: handbook/usage/interactive/README.md

duckdb_progress_display <- function(x) {
  if (x >= 100) {
    # Completion bypasses the throttle, so a completed query clears its line.
    progress_display_reset()
    return()
  }

  time <- progress_now()
  if (is.null(the$progress_last_time)) {
    the$progress_last_time <- time
  }

  min_seconds <- 0.5
  if (time - the$progress_last_time < min_seconds) {
    return()
  }

  cat(sprintf("\rDuckDB progress: %3d%%", trunc(x)))
  the$progress_last_time <- time
  the$progress_painted <- TRUE
}

# The clock the display reads, in seconds, apart so that a test can set it.
progress_now <- function() {
  as.numeric(Sys.time())
}

# Clears a painted line and restarts the throttle, at completion and when the
# next query's display is built, since a failed query never completes.
progress_display_reset <- function() {
  if (isTRUE(the$progress_painted)) {
    cat("\r                     \r")
  }
  the$progress_last_time <- NULL
  the$progress_painted <- NULL
}

get_progress_display <- function() {
  f <- getOption("duckdb.progress_display", default = is_interactive())

  if (is.null(f)) {
    f
  } else if (isTRUE(f)) {
    progress_display_reset()
    duckdb_progress_display
  } else if (is.logical(f)) {
    NULL
  } else if (is.function(f)) {
    if (length(formals(f)) > 0) {
      f
    } else {
      message(
        '`getOption("duckdb.progress_display")` is a function that has no argument, expecting at least one argument.'
      )
      options(duckdb.progress_display = NULL)
      NULL
    }
  } else {
    message(
      '`getOption("duckdb.progress_display")` is not a function, expecting either a boolean or function.'
    )
    options(duckdb.progress_display = NULL)
    NULL
  }
}

Try the duckdb package in your browser

Any scripts or data that you put into this service are public.

duckdb documentation built on Oct. 23, 2026, 5:06 p.m.