Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
averissimo opened this issue Feb 26, 2024 · 0 comments · Fixed by #696
Open

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

averissimo opened this issue Feb 26, 2024 · 0 comments · Fixed by #696
Labels
bug Something isn't working core

Comments

@averissimo
Copy link
Contributor

Some parameters of module functions are not validated with checkmate:

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

  • all that have this: pre_output, post_output
    • They are assumed to be validated by {teal.widgets} functions
  • tm_g_bivariate: facet
  • tm_g_distribution: plot_height, plot_width
  • tm_outliers: plot_height, plot_width

I propose we couple this with:

  • Reorder assertions with same parameter order
  • Adds some comments to increase readability of initial common logic
    • # Normalizing data types
    • # Start of assertions
    • # End of assertions

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

  # ...
@averissimo averissimo added bug Something isn't working core labels Feb 26, 2024
@averissimo averissimo linked a pull request Feb 27, 2024 that will close this issue
averissimo added a commit that referenced this issue Mar 1, 2024
# Pull Request

- Fixes #686
- Part of #624 

#### Changes descriptions

- Adds missing assertions described on #686 
- Adds a helper function called `assert_single_selection`
- Avoids many repetitive calls across functions to check for multiple
selections
  - Adds simple unit tests
- Adds some comments to maintain a consistent structure

---------

Signed-off-by: André Veríssimo <[email protected]>
Co-authored-by: Dawid Kałędkowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant