arg_match: A better match.arg especially for checking function inputs

View source: R/utils.R

arg_matchR Documentation

A better match.arg especially for checking function inputs

Description

Useful when specifying allowed values for a function argument in a vector in the formals. See examples.

Usage

arg_match(arg)

Arguments

arg

The name of the argument in the parent function

Value

The value of arg after verifying, or an error

Examples

## Not run: 
  my_fun <- function(my_arg = c("a", "b")) {
    my_arg <- arg_match(my_arg)
    return(paste("The value is", my_arg))
  }
  
  my_fun("a")
  my_fun("b")
  my_fun("c")
  my_fun()
  my_fun(NULL)
  my_fun(5)

## End(Not run)

bcgov/bcgroundwater documentation built on March 18, 2024, 5:43 a.m.