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

Fixes matchArg var name problem and retrieves choices from formals when missing #252

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

averissimo
Copy link

@averissimo averissimo commented Dec 12, 2023

Closes #251

Changes description

Example (when on PR branch)

🔎 note double problem in error message:

  • Assertion on character(0)... in the error message
  • ... but is not atomic scalar. in the error message
f1 <- function(x = c("aa", "bb", "cc")) {
  checkmate::matchArg(x, choices = eval(formals(f1)[["x"]]))
}
f1("dd")
#> Error in checkmate::matchArg(x, choices = eval(formals(f1)[["x"]])):
#> Assertion on 'character(0)' failed: Must be element of set {'aa','bb','cc'}, but is not atomic scalar.

checkmate::matchArg("xx", choices = c("pearson", "kendall", "spearman"))
#> Error in checkmate::matchArg("xx", choices = c("pearson", "kendall", "spearman")):
#> Assertion on 'character(0)' failed: Must be element of set {'pearson','kendall','spearman'}, but is not atomic scalar.

🟢 Corrected

pkgload::load_all("/path/to/checkmate/with/branch/from/pr")
#> ℹ Loading checkmate
f1("dd")
#> Error in f1("dd"):
#> Assertion on 'x' failed: Must be element of set {'aa','bb','cc'}, but is 'dd'.

checkmate::matchArg("xx", choices = c("pearson", "kendall", "spearman"))
#> Error in eval(expr, envir, enclos):
#> Assertion on '"xx"' failed: Must be element of set {'pearson','kendall','spearman'}, but is 'xx'.

🟢 With missing choices

f2 <- function(x = c("aa", "bb", "cc")) {
  res <- checkmate::matchArg(x)
  res
}

f2("dd")
#> Error in f2("dd"):
#> Assertion on 'x' failed: Must be element of set {'aa','bb','cc'}, but is 'dd'.

f2("aa")
#> [1] "aa"

Created on 2024-02-28 with reprex v2.0.2

@averissimo averissimo changed the title matchArg asserts .var.name and retrieves choices from formals when missing Fixes matchArg var name problem and retrieves choices from formals when missing Dec 13, 2023
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

Successfully merging this pull request may close these issues.

Original variable name does not appear when matchArg doesn't find choice
1 participant