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

Feature Request: Add null.ok = TRUE Parameter to checkmate::check_names #272

Open
mnlang opened this issue Oct 26, 2024 · 0 comments
Open

Comments

@mnlang
Copy link

mnlang commented Oct 26, 2024

Description:
I would like to request the addition of the null.ok = TRUE parameter to the checkmate::check_names function. This feature would allow for more concise and elegant input validation when checking if an object is either a list or NULL, and if it is a list, ensuring that it has specific names.

Current Limitation:
Currently, for example, the checkmate::check_list function supports the null.ok parameter, allowing us to check if an object is either a list or NULL. However, the checkmate::check_names function does not support the null.ok parameter. This limitation makes it challenging to perform both checks in a single assert call.

Proposed Usage:
With the proposed feature, the code could be simplified as follows:

foo <- function(x) {
  checkmate::assert(
    checkmate::check_list(x, null.ok = TRUE, names = "named"),
    checkmate::check_names(names(x), must.include = c("a", "b"), null.ok = TRUE) # NOTE: `null.ok` currently not a supported argument!
  )
  # ... 
}

Am I overlooking something, or what is your proposed usage? Thank you for considering this feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant