match_arg: Argument Verification Using Partial Matching

View source: R/match_arg.R

match_argR Documentation

Argument Verification Using Partial Matching

Description

match.arg matches arguments against a table of candidate values as specified by choices. Matching is done using grep, and arguments may be abbreviated. If ignore.case = TRUE, case is ignored when performing the matching.

Usage

match_arg(
  x,
  choices,
  several.ok = FALSE,
  ignore.case = FALSE,
  .var.name = checkmate::vname(x),
  comment = NULL,
  add = NULL
)

Arguments

x

[character]
User provided argument to match.

choices

[character()]
Candidates to match x with.

several.ok

[logical(1)]
If TRUE, x should be allowed to have more than one element.

ignore.case

[logical(1)]
Case is ignored if TRUE. Default is FALSE.

.var.name

[character(1)]
Name of the checked object to print in error messages. Defaults to the heuristic implemented in vname.

comment

[character(1)]
Extra information to be appended to the standard error message in assertions.

add

[AssertCollection]
Collection to store assertions. See AssertCollection.

Details

Partial Argument Matching

This is an extensions to matchArg with support for ignore.case and comment. matchArg is an extension of match.arg with support for AssertCollection. The behavior is very similar to match.arg, with a few exceptions:

  • NULL is not a valid value for x.

  • When several.ok = TRUE, it is required that all values for x match a value in choices and that each value in x matches only one value in choices.

  • When several.ok = FALSE, it is required that length(x) == 1 and that x matches one and only one value in choices.

Value

Character vector with subset of choices.

Examples

match_arg("a", choices = c("Apple", "Banana"), ignore.case = TRUE)
match_arg(c("a", "Ban"), choices = c("Apple", "Banana"), several.ok = TRUE, ignore.case = TRUE)

NorwegianVeterinaryInstitute/NVIcheckmate documentation built on Dec. 14, 2024, 10:43 p.m.