insightsengineering / teal.modules.general

General Purpose Teal Modules
https://insightsengineering.github.io/teal.modules.general/
Other
9 stars 13 forks source link

[Bug]: Some public `tm_` module parameters are not checked and unordered #686

Open averissimo opened 8 months ago

averissimo commented 8 months ago

Some parameters of module functions are not validated with checkmate:

Here's a survey (that may not be complete):

I propose we couple this with:

Example:

tm_g_foo <- function(label = "Regression Analysis",
                     regressor,
                     response,
                     shape = shape_names,
                     ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void")) {
  logger::log_info("Initializing tm_g_foo")

  # Normalize the parameters
  if (inherits(regressor, "data_extract_spec")) regressor <- list(regressor)
  if (inherits(response, "data_extract_spec")) response <- list(response)

  # Start of assertions
  checkmate::assert_string(label)
  checkmate::assert_list(regressor, types = "data_extract_spec")
  checkmate::assert_list(response, types = "data_extract_spec")
  if (!all(vapply(response, function(x) !(x$select$multiple), logical(1)))) {
    stop("'response' should not allow multiple selection")
  }

  checkmate::assert_character(shape)
  ggtheme <- match.arg(ggtheme)
  # End of assertions

  # ...