Skip to content

Commit

Permalink
Use rlang::is_interactive() (#1360)
Browse files Browse the repository at this point in the history
* Use rlang::is_interactive()

Closes #1356

* Wording

* Add NEWS bullet

* Apparently readr does not import rlang's namespace
  • Loading branch information
jennybc authored Jan 26, 2022
1 parent 90736aa commit bfeb752
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* `read_table()`, `read_log()`, and `read_delim_chunked()` (and friends) gain the `show_col_types` argument found elsewhere. All `read_*()` functions now respect the `show_col_types` argument or option even when using the first edition parsing engine (#1331).

* `show_progress()` uses `rlang::is_interactive()` instead of `base::interactive()` (#1356).

# readr 2.1.1

* Jenny Bryan is now the maintainer.
Expand Down
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
#' `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")) &&
rlang::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 bfeb752

Please sign in to comment.