match_arg: Match arguments

Description Usage Arguments Details Value See Also Examples

View source: R/match-arg.R

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

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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 July 16, 2021, 9:07 a.m.