Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make is_interactive() sensitive to TESTTHAT env var #738

jennybc opened this issue Mar 12, 2019 · 1 comment


None yet
2 participants
Copy link

commented Mar 12, 2019

I'm considering replacing this DIY solution:

is_testing <- function() {
  identical(Sys.getenv("TESTTHAT"), "true")

interactive <- function() {
  base::interactive() && !is_testing()

with rlang::is_interactive(). But the rlang function doesn't help me with the testthat scenario.


Lines 92 to 129 in 79f8d57

#' Is R running interactively?
#' @description
#' Like [base::interactive()], `is_interactive()` returns `TRUE` when
#' the function runs interactively and `FALSE` when it runs in batch
#' mode. It also checks:
#' * Whether knitr or an RStudio notebook is in progress.
#' * The `rlang_interactive` global option. If set to a single `TRUE`
#' or `FALSE`, `is_interactive()` returns that value instead. This
#' escape hatch is useful in unit tests or to manually turn on
#' interactive features in RMarkdown outputs.
#' `with_interactive()` and `scoped_interactive()` set the global
#' option conveniently.
#' @export
is_interactive <- function() {
opt <- peek_option("rlang_interactive")
if (!is_null(opt)) {
if (!is_bool(opt)) {
options(rlang_interactive = NULL)
abort("`rlang_interactive` must be a single `TRUE` of `FALSE`")
if (is_true(peek_option(""))) {
if (is_true(peek_option("rstudio.notebook.executing"))) {

Does it make sense to add identical(Sys.getenv("TESTTHAT"), "true") to the conditions for which rlang::is_interactive() returns FALSE?


This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2019

I guess the other way to solve this is in testthat: set the rlang_interactive option to FALSE over there, in any place where we currently set the TESTTHAT env var to "true".

jennybc added a commit that referenced this issue Apr 16, 2019

@jennybc jennybc closed this in #761 Apr 19, 2019

jennybc added a commit that referenced this issue Apr 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.