validate_parameter: validate_parameter, vp

Description Usage Arguments Value Examples

Description

A friendly function to simplify the validation of function or method input parameters.

validate_parameter

The original function name.

vp

A shortcut function alias.

Usage

1
2
3
4
5
6
7
validate_parameter(parameter_value, default_value = NULL, category = NULL,
  parameter_length = NULL, acceptable_values = NULL, limit_min = NULL,
  limit_max = NULL, verbosity = NULL, ...)

vp(parameter_value, default_value = NULL, category = NULL,
  parameter_length = NULL, acceptable_values = NULL, limit_min = NULL,
  limit_max = NULL, verbosity = NULL, ...)

Arguments

parameter_value

The original function or method parameter.

default_value

A default value to be substituted if parameter_value is NULL, NA, etc. (see is_void()).

category

One of the following strings: "character", "numeric", "logical".

parameter_length

Often, parameters are received as vectors. Often, functions and methods only support vectors of size 1 or sometimes of a very specific length.

acceptable_values

A list of of acceptable values. Any attempt to use a value not listed will raise an error. This is obvious, but note that "default_value" is applied before validation takes place against the list of acceptable values.

Value

The validated (sometimes coerced) parameter, possibly the default value. Sometimes, accompanied with warnings. If not coerction is possible, raises an error.

Examples

1
2
3
4
validate_parameter(NULL, 2, "Numeric", 1)
vp(NA ,5, "Numeric", 1)
vp(c("a", "b"), c("c", "d"), "String", 2)
vp(c("a", "b"), NULL, "character", 2, c("a", "b", "c"))

daviddoret/GRCRToolkit documentation built on May 23, 2019, 7:31 a.m.