inspect_categories: Validate factor levels

Description Usage Arguments Details Value See Also Examples

View source: R/inspect_.R

Description

inspect_categories checks if an object is eligible to be used as the levels of a factor. This can be useful to validate inputs in user-defined functions.

Usage

1

Arguments

x

An arbitrary object.

Details

inspect_categories conducts a series of tests to check if x is eligible to be used as the levels of a factor. Namely, inspect_categories checks if:

Value

inspect_categories does not return any output. There are two possible outcomes:

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Calls that pass silently:
x1 <- 1:5
x2 <- c("yes", "no")
x3 <- c(TRUE, FALSE)
x4 <- factor(c("smoker", "non-smoker"))
x5 <- factor(c("yes", "no", "yes"))
inspect_categories(x1)
inspect_categories(x2)
inspect_categories(x3)
inspect_categories(x4)
inspect_categories(levels(x5))

# Calls that throw informative error messages:
y1 <- c(1, 1:5)
y2 <- c("yes", "no", "yes")
y3 <- factor(c("yes", "no", "yes"))
try(inspect_categories(y1))
try(inspect_categories(y2))
try(inspect_categories(y3))
try(mylist <- list(
  NULL, numeric(0),
  complex(1), list(10), NaN, NA
))
try(inspect_categories(mylist[[1]]))
try(inspect_categories(mylist[[2]]))
try(inspect_categories(mylist[[3]]))
try(inspect_categories(mylist[[4]]))
try(inspect_categories(mylist[[5]]))
try(inspect_categories(mylist[[6]]))

inspector documentation built on June 18, 2021, 1:06 a.m.