arg_match

0th

Percentile

Match an argument to a character vector

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

  • Partial matches trigger an error.

  • Error messages are a bit more informative and obey the tidyverse standards.

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.

Aliases
  • arg_match
Examples
# NOT RUN {
fn <- function(x = c("foo", "bar")) arg_match(x)
fn("bar")

# This would throw an informative error if run:
# fn("b")
# fn("baz")
# }
Documentation reproduced from package rlang, version 0.1.6, License: GPL-3

Community examples

Looks like there are no examples yet.