Skip to main content

MATCH_ARG_HELPER

Constant MATCH_ARG_HELPER 

Source
const MATCH_ARG_HELPER: &str = "# Internal helper: scalar `match.arg()` for `match_arg` / `choices` params.\n# `base::match.arg()` says `\'arg\'` in its messages and reports its own frame;\n# this names the argument and raises an argument error\n# (`.miniextendr_arg_error`) attributed to `call`: by default the wrapper\'s own\n# call, for a `call = caller` wrapper its caller\'s matched call.\n# Semantics follow `match.arg(arg, choices)`: `NULL` and the full choice vector\n# (the formal default) select the first choice; otherwise exactly one string\n# that matches a choice exactly or as a unique prefix. A factor is read as its\n# labels. `aliases`, a named character vector (`c(grey = \"gray\")`), maps a\n# string typed exactly as an alias to its choice; a prefix of an alias is not\n# one. `listed` is the text the message names the listed aliases with after\n# the choices (` (or \"grey\" for \"gray\")`, empty when none is listed). The\n# Rust side\'s `match_arg_param()` gives a body the same results and messages\n# for a choice argument it matches itself.\n.miniextendr_match_arg <- function(arg, choices, arg_name, call = sys.call(-1L), aliases = NULL, listed = \"\") {\n  if (is.null(arg)) return(choices[[1L]])\n  if (is.factor(arg)) arg <- as.character(arg)\n  if (!is.character(arg)) .miniextendr_arg_error(arg_name, \"must be NULL or a character vector\", call)\n  if (identical(arg, choices)) return(arg[[1L]])\n  if (length(arg) != 1L) .miniextendr_arg_error(arg_name, \"must be of length 1\", call)\n  if (!is.null(aliases) && !is.na(a <- match(arg, names(aliases)))) return(aliases[[a]])\n  i <- pmatch(arg, choices, nomatch = 0L, duplicates.ok = TRUE)\n  if (is.na(i) || i == 0L) {\n    .miniextendr_arg_error(arg_name, sprintf(\"should be one of %s%s\", paste(dQuote(choices, FALSE), collapse = \", \"), listed), call)\n  }\n  choices[[i]]\n}\n";