match_arg: Match arguments

View source: R/match-arg.R

match_argR Documentation

Match arguments

Description

This function is essentially a clear version of base::match.arg() which produces a cleaner warning message and does not restrict the table param to character vectors only.

Usage

match_arg(x, table)

Arguments

x

An argument

table

A table of choices

Details

Match arguments

Value

A single value from x matched on table

See Also

match_param()

Examples

x <- c("apple", "banana", "orange")
match_arg("b", x)

# Produces error
try(match_arg("pear", x))

foo <- function(x, op = c(1, 2, 3)) {
  op <- match_arg(op)
  x / op
}

foo(10, 3)

# Error
try(foo(1, 0))

mark documentation built on Aug. 7, 2022, 1:05 a.m.