Description Usage Arguments Details Value See Also Examples
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.
1 |
x |
An arbitrary object. |
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:
x
is NULL
or empty.
x
is atomic.
x
has an eligible data type (logical, integer, double, character).
There are NA
or NaN
values in x
.
There are repeated values in x
.
inspect_categories
does not return any output. There are two
possible outcomes:
The call is silent if x
is eligible to be used as the levels of a factor.
An informative error message is thrown otherwise.
inspect_data_dichotomous
to validate dichotomous
data.
inspect_data_categorical
and
inspect_data_cat_as_dichotom
to validate categorical
data.
inspect_par_bernoulli
to validate
Bernoulli/Binomial proportions.
inspect_par_multinomial
to validate vectors of
Multinomial proportions.
inspect_character
to validate character vectors.
inspect_character_match
to validate character
vectors with predefined allowed values.
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]]))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.