Closed bpbond closed 8 months ago
See https://github.com/COMPASS-DOE/whattheflux/pull/14 for a simple implementation example.
Have some code that will set quiet messaging options. However, need to revisit this issue to figure out how to set options upon loading the package.
Currently doing this:
# Set an option to control whether messages and warning are suppressed.
# Defaults to verbose messaging.
options("matilda.verbose" = FALSE)
# Quiet messages
#' Suppressing messages in Matilda functions
#'
#' @param ... Message to print if verbosity option is set to TRUE.
#'
#' @export
#'
matilda_message <- function(...) {
# Get the current verbose option setting
message.option <- getOption("matilda.verbose")
# Check if the verbose option is set to FALSE
if (message.option == FALSE) {
# If FALSE, exit function without displaying message
return()
}
# If verbose option is TRUE, display message
message(...)
}
But the option default is not being set in the package upon loading:
> getOption("matilda.verbose")
NULL
Tasks:
options()
default upon loading the package.Changes to be made in the enhancements/quiet-messaging
branch
Hi @jk-brown I would suggest doing
message.option <- getOption("matilda.verbose", default = TRUE) # or FALSE if you prefer
This way, if the user hasn't set an option, you assume TRUE, but if they have set it, you respect their choice.
Also message.option
is an ambiguous and verbose :) parameter name. Consider something like
verbose <- getOption("matilda.verbose", default = TRUE)
if (verbose) {
# If verbose option is TRUE, display message
message(...)
}
which to my eye makes it much clearer what's going on.
https://ropensci.org/blog/2024/02/06/verbosity-control-packages/