JGCRI / matilda

A probabilistic framework for the Hector simple climate model
Other
5 stars 3 forks source link

Verbosity #76

Closed bpbond closed 8 months ago

bpbond commented 9 months ago

https://ropensci.org/blog/2024/02/06/verbosity-control-packages/

bpbond commented 9 months ago

See https://github.com/COMPASS-DOE/whattheflux/pull/14 for a simple implementation example.

jk-brown commented 8 months ago

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:

Changes to be made in the enhancements/quiet-messaging branch

bpbond commented 8 months ago

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.

bpbond commented 8 months ago

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.