Learn R Programming

mark (version 0.8.2)

match_arg: 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)

Value

A single value from x matched on table

Arguments

x

An argument

table

A table of choices

Details

Match arguments

See Also

match_param()

Examples

Run this code
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))

Run the code above in your browser using DataLab