Learn R Programming

chk (version 0.4.0)

check_values: Check Values and Class

Description

Checks values and S3 class of an atomic object.

Usage

check_values(x, values, x_name = NULL)

Arguments

x

The object to check.

values

An atomic vector specifying the S3 class and possible values.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails.

Details

To check the class simply pass a vector of the desired class.

To check that x does not include missing values pass a single non-missing value (of the correct class).

To allow it to include missing values include a missing value.

To check that it only includes missing values only pass a missing value (of the correct class).

To check the range of the values in x pass two non-missing values (as well as the missing value if required).

To check that x only includes specific values pass three or more non-missing values.

See Also

Other check: check_data(), check_dim(), check_key(), check_names()

Examples

Run this code
# NOT RUN {
check_values(1, numeric(0))
check_values(1, 2)
try(check_values(1, 1L))
try(check_values(NA_real_, 1))
# }

Run the code above in your browser using DataLab