arg_match {rlang}R Documentation

Match an argument to a character vector

Description

This is equivalent to base::match.arg() with a few differences:

Usage

arg_match(arg, values = NULL)

Arguments

arg

A symbol referring to an argument accepting strings.

values

The possible values that arg can take. If NULL, the values are taken from the function definition of the caller frame.

Value

The string supplied to arg.

Examples

fn <- function(x = c("foo", "bar")) arg_match(x)
fn("bar")

# This would throw an informative error if run:
# fn("b")
# fn("baz")

[Package rlang version 0.2.2 Index]