-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and update message handling
Add test for build_collection_index New internal bf_msg() handles printing messages New internal bf_suppress_msg() blocks messages
- Loading branch information
1 parent
5992ba0
commit 391d5db
Showing
21 changed files
with
333 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#' Internal function to send a message from within BirdFlow functions | ||
#' | ||
#' It checks to see if BirdFlowR is in verbose mode | ||
#' (`birdflow_options("verbose"`) and if so pastes it's arguments together | ||
#' and prints the result with `cat()`. | ||
#' In the future it might be updated to use `message()` | ||
#' | ||
#' @param ... Text that will be pasted together to make a message. | ||
#' @param sep (optional) separator between text elements in `...` | ||
#' defaults to no separation. | ||
#' | ||
#' @return Nothing is returned if verbose is TRUE the message is printed. | ||
#' | ||
#' @keywords internal | ||
#' @seealso [birdflow_options()] for changing verbosity. | ||
bf_msg <- function(..., sep = "") { | ||
m <- paste(..., sep = sep) | ||
if (birdflow_options("verbose")) { | ||
cat(m) | ||
} | ||
} | ||
|
||
|
||
|
||
#' Conditionally suppress messages from expressions in BirdFlowR code | ||
#' | ||
#' This internal functions is used to suppress messages thrown | ||
#' by functions called in BirdFlowR code if `birdflow_options("verbose")` | ||
#' is `FALSE`. | ||
#' | ||
#' @param exp R code that might throw a message (originating outside of | ||
#' pkg{BirdFlowR}. | ||
#' @keywords internal | ||
#' @seealso [preprocess_species()] uses this when calling \pkg{ebirdst} | ||
#' functions that display messages. | ||
#' When BirdFlowR functions generate messages they should use [bf_msg()] so that | ||
#' `birdflow_options("verbose")` is honored. | ||
#' @examples | ||
#' \dontrun{ | ||
#' # bf_suppress_msg isn't exported so can't be run in examples | ||
#' # in internal code or after devtools::load_all() example will work | ||
#' ob <- birdflow_options("verbose") | ||
#' birdflow_options(verbose = FALSE) | ||
#' bf_suppress_msg( message("hi" )) | ||
#' birdflow_options(verbose = TRUE) | ||
#' bf_suppress_msg( message("hi" )) | ||
#' birdflow_options(ob) | ||
#' } | ||
#' | ||
bf_suppress_msg <- function(exp) { | ||
verbose <- birdflow_options("verbose") | ||
withCallingHandlers( | ||
message = function(m) { | ||
if (!verbose) | ||
tryInvokeRestart("muffleMessage") | ||
}, | ||
exp | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.