check_arg: Check/Validate Arguments

Description Usage Arguments Details Value Examples

Description

Check that the arguments passed for a parameter are in a set of valid values, and throw a warning & return a default value if validation fails.

Usage

1
check_arg(arg, name, val, validVals, silent = FALSE)

Arguments

arg

The parameter name to validate values for (character scalar).

name

The name of the current loop variable (character scalar).

val

The value of the current loop variable.

validVals

A vector/list of the valid values that the parameter can take.

silent

Whether to silence the warning that usually appears when validation fails (boolean scalar).

Details

This is an internal function meant to be called unconditionally inside a loop. It will only perform validation if arg == name.

Value

If ! val %in% validVals, validVals[1] will be returned, else val.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Valid value, "apple" is returned
check_arg("fruit", "fruit", "apple", c("apple", "banana", "cherry"))

# Invalid value, "banana" is returned
check_arg("fruit", "fruit", "apple", c("banana", "cherry"), silent = TRUE)

# Throws a warning
## Not run: 
  check_arg("fruit", "fruit", "apple", c("banana", "cherry"))

## End(Not run)

KO112/chartjs documentation built on Aug. 6, 2020, 2:35 p.m.