Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use rlang::is_interactive() instead of base::interactive()
  • Loading branch information
schloerke committed Oct 5, 2022
commit 777cf62c1c25a992c8a8666cf40790964669ec6a
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* When mounting a router at an existing location, the old mounted router is removed and the router to be mounted is added to the end of the mount list (default; `after = NULL`). This makes it so prior mount calls do not affect current mount calls. (#882)

* The default value of `debug` has been changed from `base::interactive()` to `rlang::is_interactive()`. This allows for tests to be consistent when run interactively or in batch mode. (#882)

## New features

* Added support for `pr_mount(after=)` / `Plumber$mount(after=)` which allows for mounts to be added in non-sequential order (#882)
Expand Down
12 changes: 7 additions & 5 deletions R/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Plumber <- R6Class(
#' Mac OS X, port numbers smaller than 1025 require root privileges.
#'
#' This value does not need to be explicitly assigned. To explicitly set it, see [options_plumber()].
#' @param debug If `TRUE`, it will provide more insight into your API errors. Using this value will only last for the duration of the run. If a `$setDebug()` has not been called, `debug` will default to `interactive()` at `$run()` time. See `$setDebug()` for more details.
#' @param debug If `TRUE`, it will provide more insight into your API errors. Using this value will only last for the duration of the run. If a `$setDebug()` has not been called, `debug` will default to [`rlang::is_interactive()`] at `$run()` time. See `$setDebug()` for more details.
#' @param swagger Deprecated. Please use `docs` instead. See `$setDocs(docs)` or `$setApiSpec()` for more customization.
#' @param swaggerCallback An optional single-argument function that is
#' called back with the URL to an OpenAPI user interface when one becomes
Expand Down Expand Up @@ -232,7 +232,7 @@ Plumber <- R6Class(
}, add = TRUE)
# Fix the debug value while running.
self$setDebug(
# Order: Run method param, internally set value, is interactive()
# Order: Run method param, internally set value, `is_interactive()`
# `$getDebug()` is dynamic given `setDebug()` has never been called.
rlang::maybe_missing(debug, self$getDebug())
)
Expand Down Expand Up @@ -979,11 +979,11 @@ Plumber <- R6Class(
#'
#' See also: `$getDebug()` and [pr_set_debug()]
#' @param debug `TRUE` provides more insight into your API errors.
setDebug = function(debug = interactive()) {
setDebug = function(debug = is_interactive()) {
stopifnot(length(debug) == 1)
private$debug <- isTRUE(debug)
},
#' @description Retrieve the `debug` value. If it has never been set, the result of `interactive()` will be used.
#' @description Retrieve the `debug` value. If it has never been set, the result of [`rlang::is_interactive()`] will be used.
#'
#' See also: `$getDebug()` and [pr_set_debug()]
getDebug = function() {
Expand Down Expand Up @@ -1351,8 +1351,10 @@ upgrade_docs_parameter <- function(docs, ...) {



#' @importFrom rlang is_interactive
# Method needed for testing mocking
default_debug <- function() {
interactive()
is_interactive()
}


Expand Down
2 changes: 1 addition & 1 deletion R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pr_filter <- function(pr,
#' @param ... Should be empty.
#' @param debug If `TRUE`, it will provide more insight into your API errors.
#' Using this value will only last for the duration of the run.
#' If [pr_set_debug()] has not been called, `debug` will default to `interactive()` at [pr_run()] time
#' If [pr_set_debug()] has not been called, `debug` will default to [`rlang::is_interactive()`] at [pr_run()] time
#' @param docs Visual documentation value to use while running the API.
#' This value will only be used while running the router.
#' If missing, defaults to information previously set with [pr_set_docs()].
Expand Down
4 changes: 2 additions & 2 deletions R/pr_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pr_set_error <- function(pr, fun) {
#' Set debug value to include error messages of routes cause an error
#'
#' To hide any error messages in production, set the debug value to `FALSE`.
#' The `debug` value is enabled by default for [interactive()] sessions.
#' The `debug` value is enabled by default for [`rlang::is_interactive()`] sessions.
#'
#' @template param_pr
#' @param debug `TRUE` provides more insight into your API errors.
Expand All @@ -118,7 +118,7 @@ pr_set_error <- function(pr, fun) {
#' pr_get("/boom", function() stop("boom")) %>%
#' pr_run()
#' }
pr_set_debug <- function(pr, debug = interactive()) {
pr_set_debug <- function(pr, debug = is_interactive()) {
validate_pr(pr)
pr$setDebug(debug = debug)
pr
Expand Down