Skip to content

Commit

Permalink
Use rlang::is_interactive()
Browse files Browse the repository at this point in the history
Closes #1356
  • Loading branch information
jennybc committed Jan 26, 2022
1 parent 90736aa commit f985b5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
24 changes: 15 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ is_syntactic <- function(x) make.names(x) == x

#' Determine whether progress bars should be shown
#'
#' Progress bars are shown _unless_ one of the following is `TRUE`
#' - The bar is explicitly disabled by setting `options(readr.show_progress = FALSE)`
#' - The code is run in a non-interactive session (`interactive()` is `FALSE`).
#' - The code is run in an RStudio notebook chunk.
#' - The code is run by knitr / rmarkdown.
#' By default, readr shows progress bars. However, progress reporting is
#' suppressed if any of the following conditions hold:
#' - The bar is explicitly disabled by setting
#' `options(readr.show_progress = FALSE)`.
#' - The code is run in a non-interactive session, as determined by
#' [rlang::is_interactive()].
#' - The code is run in an RStudio notebook chunk, as determined by the
#' `getOption("rstudio.notebook.executing")`.
#' @export
show_progress <- function() {
isTRUE(getOption("readr.show_progress")) && # user disables progress bar
interactive() && # an interactive session
!isTRUE(getOption("rstudio.notebook.executing")) && # Not running in an RStudio notebook chunk
!isTRUE(getOption("knitr.in.progress")) # Not actively knitting a document
isTRUE(getOption("readr.show_progress")) &&
is_interactive() &&
# some analysis re: rstudio.notebook.executing can be found in:
# https://github.com/r-lib/rlang/issues/1031
# TL;DR it's not consulted by is_interactive(), but probably should be
# consulted for progress reporting specifically
!isTRUE(getOption("rstudio.notebook.executing"))
}

#' Determine whether column types should be shown
Expand Down
13 changes: 8 additions & 5 deletions man/show_progress.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f985b5f

Please sign in to comment.