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

handle names in match_param() better #194

Closed
jmbarbone opened this issue Jun 28, 2023 · 0 comments
Closed

handle names in match_param() better #194

jmbarbone opened this issue Jun 28, 2023 · 0 comments
Assignees
Labels
bug 🐛 Something isn't working documentation ✏️ Improvements or additions to documentation new feature 🎁 New feature request
Milestone

Comments

@jmbarbone
Copy link
Owner

jmbarbone commented Jun 28, 2023

Found some accidental name selection matching.

library(mark)

# using names should only work when choices is a `list`

values <- list(a = 1, b = 2)
foo <- function(x = values) {
  match_param(x)
}

foo(1)
#> [1] "a"
foo(2)
#> [1] "b"

# otherwise, there may be accidents

values <- c(a = 1, b = 2)
foo <- function(x = values) {
  match_param(x)
}

foo(1)
#> [1] "a"
foo(2)
#> [1] "b"
try(foo(3))
#> Error : <matchParamMatchError> `match_param(x)` failed in `foo(3)`:
#>   `x` [3] must be one of the following: "1", "2"
#> package:mark

Created on 2023-06-28 with reprex v2.0.2

Maybe include an argument names = is.list(choices) may be better for handling this.

Maybe include a better error message with names

`x` [3]` must be one of the following: a:"1", b:"2"
@jmbarbone jmbarbone added bug 🐛 Something isn't working new feature 🎁 New feature request documentation ✏️ Improvements or additions to documentation labels Jun 28, 2023
@jmbarbone jmbarbone self-assigned this Jun 28, 2023
@jmbarbone jmbarbone added this to the 0.8.0 milestone Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working documentation ✏️ Improvements or additions to documentation new feature 🎁 New feature request
Projects
None yet
Development

No branches or pull requests

1 participant