inspect_data_categorical {inspector}R Documentation

Validate categorical data

Description

inspect_data_categorical checks if an object contains data that is eligible to have been generated by a Multinomial distribution. This can be useful to validate inputs in user-defined functions.

Usage

inspect_data_categorical(data, allow_nas = TRUE, warning_nas = FALSE)

Arguments

data

An arbitrary object.

allow_nas

Logical value. If TRUE then NA and NaN values in data are allowed. If FALSE, execution is stopped and an error message is thrown in case there are NA or NaN values in data.

warning_nas

Logical value. If TRUE then the presence of NA or NaN values in data generates a warning message. NA and NaN values pass silently otherwise (if allow_nas is set toTRUE).

Details

inspect_data_categorical conducts a series of tests to check if data is eligible to have been generated by a Multinomial distribution. Namely, inspect_data_categorical checks if:

Value

inspect_data_categorical does not return any output. There are three possible outcomes:

See Also

Examples

# Calls that pass silently:
x1 <- c(1, 0, 0, 1, 2)
x2 <- c(FALSE, FALSE, TRUE, NA)
x3 <- c("yes", "no", "yes", "maybe")
x4 <- factor(c("yes", "no", "yes", "maybe"))
x5 <- c(1, 0, 0, 1, 0, NA, 2)
inspect_data_categorical(x1)
inspect_data_categorical(x2)
inspect_data_categorical(x3)
inspect_data_categorical(x4)
inspect_data_categorical(x5)
inspect_data_categorical(x5)

# Call that throws an informative warning message:
y1 <- c(1, 1, NA, 0, 0, 2)
try(inspect_data_categorical(y1, warning_nas = TRUE))

# Calls that throw an informative error message:
z <- c(1, 1, NA, 0, 0, 2)
try(inspect_data_categorical(z, allow_nas = FALSE))
try(inspect_data_categorical(NULL))
try(inspect_data_categorical(list(1, 0)))
try(inspect_data_categorical(numeric(0)))
try(inspect_data_categorical(NaN))
try(inspect_data_categorical(NA))

[Package inspector version 1.0.3 Index]