norm_type: Argument checking

Description Usage Arguments Value Examples

Description

These functions are for checking that arguments of parent functions are as expected.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
norm_type_or_null(
  x,
  type,
  length = 1,
  allow_NAs = FALSE,
  arg = deparse(substitute(x))
)

norm_type(x, type, length = 1, allow_NAs = FALSE, arg = deparse(substitute(x)))

## S4 method for signature 'ANY,numeric'
norm_type(x, type, length = 1, allow_NAs = FALSE, arg = deparse(substitute(x)))

## S4 method for signature 'ANY,integer'
norm_type(x, type, length = 1, allow_NAs = FALSE, arg = deparse(substitute(x)))

Arguments

x

An argument to check.

type

A vector of the expected type, typically of length 0.

length

An integer(1) or NULL for the expected length. When set to NULL, length can be anything.

allow_NAs

A logical(1), when TRUE, allows the x argument to have NAs. If FALSE, raises error when x contains NAs.

arg

A character(1) for the argument being checked. This is used to identify the argument in error messaging. Defaults to the symbol used for x.

Value

It returns x if it satisfies the criteria, or x coerced to the type class when appropriate.

Examples

1
2
# Rounding of `numeric` to `integer`
norm_type(1.26, integer())

teunbrand/tornadoplot documentation built on Dec. 23, 2021, 8:48 a.m.