| Type: | Package |
| Title: | Validation of Arguments and Objects in User-Defined Functions |
| Version: | 1.0.3 |
| Description: | Utility functions that implement and automate common sets of validation tasks. These functions are particularly useful to validate inputs, intermediate objects and output values in user-defined functions, resulting in tidier and less verbose functions. |
| License: | MIT + file LICENSE |
| URL: | https://ptfonseca.github.io/inspector/, https://github.com/ptfonseca/inspector |
| BugReports: | https://github.com/ptfonseca/inspector/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 2.10) |
| Imports: | Rdpack (≥ 0.7) |
| Suggests: | covr (≥ 3.5.0), knitr (≥ 1.28), rmarkdown (≥ 2.1), testthat (≥ 2.3.2), pcal (≥ 1.0.0) |
| RdMacros: | Rdpack |
| RoxygenNote: | 7.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2021-06-17 18:34:03 UTC; pedro |
| Author: | Pedro Fonseca |
| Maintainer: | Pedro Fonseca <pedro.teles.fonseca@phd.iseg.ulisboa.pt> |
| Repository: | CRAN |
| Date/Publication: | 2021-06-17 19:00:02 UTC |
Package 'inspector'
Description
The inspector package provides utility functions that
implement and automate common sets of validation tasks. These functions are
particularly useful to validate inputs, intermediate objects and output
values in user-defined functions, resulting in tidier and less verbose
functions.
Details
For a complete list of functions see library(help = "inspector").
For instructions and examples see the "Usage" section of the
README.
Author(s)
Maintainer: Pedro Fonseca pedro.teles.fonseca@phd.iseg.ulisboa.pt (ORCID)
Other contributors:
FCT [funder]
See Also
Useful links:
Report bugs at https://github.com/ptfonseca/inspector/issues
Validate vectors of Bayes factors
Description
inspect_bfactor checks if an object is a numeric vector of
valid Bayes factor values. This can be useful to validate inputs,
intermediate calculations or outputs in user-defined functions.
Usage
inspect_bfactor(x, allow_nas = TRUE, warning_nas = TRUE)
Arguments
x |
An arbitrary object. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_bfactor conducts a series of tests to check if x is a
numeric vector of valid Bayes factor values. Namely, inspect_bfactor checks
if:
-
xisNULLor empty. -
xis an atomic vector. -
xis numeric. -
xhasNAorNaNvalues. The values of
xare non-negative.
Value
inspect_bfactor does not return any output. There are three
possible outcomes:
The call is silent if:
-
xis a numeric vector of valid Bayes factor values and there are noNAorNaNvalues inx. -
xis a numeric vector of valid Bayes factor values, there are someNAorNaNvalues inx,allow_nasis set toTRUEandwarning_nasis set toFALSE.
-
An informative warning message is given if
xis a numeric vector of valid Bayes factor values, there are someNAorNaNvalues inxand bothallow_nasandwarning_nasare set toTRUE.An informative error message is thrown and the execution is stopped if:
-
xis not a numeric vector of valid Bayes factor values. -
xis a numeric vector of valid Bayes factor values, there are some inNAorNaNvalues inxandallow_nasis set toFALSE.
-
See Also
-
inspect_bfactor_logto check if an object is a numeric vector of valid logarithmic Bayes factor values. -
bfactor_interpretfor the interpretation of Bayes factors. -
inspect_bfactor_scaleto check if an object is a valid Bayes factor interpretation scale.
Examples
# Calls that pass silently:
x1 <- c(0, 0.5, 1, 10, 50, 100)
x2 <- c(NA, 0.5, 1, 10, 50, 100)
inspect_bfactor(x1)
inspect_bfactor(x2, warning_nas = FALSE)
inspect_bfactor(x2, allow_nas = TRUE, warning_nas = FALSE)
# Call that throws an informative warning message:
y <- c(0.1, 0.2, NA, 0.4, 0.5)
try(inspect_bfactor(y))
try(inspect_bfactor(y, warning_nas = TRUE))
try(inspect_bfactor(y, allow_nas = TRUE, warning_nas = TRUE))
# Calls that throw informative error messages:
z <- c(-0.9, 0, 0.1, 0.2, 0.3, 0.4, 0.5)
try(inspect_bfactor(z))
mylist <- list(
NULL, TRUE, factor(.5), matrix(0.5),
"0.5", list(0.5), NA, NaN, numeric(0), -0.5, -5
)
try(inspect_bfactor(mylist[[1]]))
try(inspect_bfactor(mylist[[2]]))
try(inspect_bfactor(mylist[[3]]))
try(inspect_bfactor(mylist[[4]]))
try(inspect_bfactor(mylist[[5]]))
try(inspect_bfactor(mylist[[6]]))
try(inspect_bfactor(mylist[[7]]))
try(inspect_bfactor(mylist[[8]]))
try(inspect_bfactor(mylist[[9]]))
try(inspect_bfactor(mylist[[10]]))
try(inspect_bfactor(mylist[[11]]))
Validate vectors of logarithmic Bayes factors
Description
inspect_bfactor_log checks if an object is a numeric vector
of valid logarithmic Bayes factor values. This can be useful to validate
inputs, intermediate calculations or outputs in user-defined functions.
Usage
inspect_bfactor_log(x, allow_nas = TRUE, warning_nas = TRUE)
Arguments
x |
An arbitrary object. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_bfactor_log conducts a series of tests to check if x is
a numeric vector of valid logarithmic Bayes factor values. Namely,
inspect_bfactor_log checks if:
-
xisNULLor empty. -
xis an atomic vector. -
xis numeric. -
xhasNAorNaNvalues.
Value
inspect_bfactor_log does not return any output. There are three
possible outcomes:
The call is silent if:
-
xis a numeric vector of valid logarithmic Bayes factor values and there are noNAorNaNvalues inx. -
xis a numeric vector of valid logarithmic Bayes factor values, there are someNAorNaNvalues inx,allow_nasis set toTRUEandwarning_nasis set toFALSE.
-
An informative warning message is given if
xis a numeric vector of valid logarithmic Bayes factor values, there are someNAorNaNvalues inxand bothallow_nasandwarning_nasare set toTRUE.An informative error message is thrown and the execution is stopped if:
-
xis not a numeric vector of valid logarithmic Bayes factor values. -
xis a numeric vector of valid logarithmic Bayes factor values, there are someNAorNaNvalues inxandallow_nasis set toFALSE.
-
See Also
-
inspect_bfactorto check if an object is a numeric vector of valid Bayes factor values. -
bfactor_log_interpretfor the interpretation of the logarithms of Bayes factors. -
inspect_bfactor_scaleto check if an object is a Bayes factor interpretation scale. -
inspect_log_baseto check if an object is an eligible logarithmic base.
Examples
# Calls that pass silently:
x1 <- c(0, 0.5, 1, 10, 50, 100)
x2 <- c(NA, 0.5, 1, 10, 50, 100)
inspect_bfactor_log(x1)
inspect_bfactor_log(x2, warning_nas = FALSE)
inspect_bfactor_log(x2, allow_nas = TRUE, warning_nas = FALSE)
# Call that throws an informative warning message:
y <- c(0.1, 0.2, NA, 0.4, 0.5)
try(inspect_bfactor_log(y))
try(inspect_bfactor_log(y, warning_nas = TRUE))
try(inspect_bfactor_log(y, allow_nas = TRUE, warning_nas = TRUE))
# Calls that throw informative error messages:
mylist <- list(
NULL, TRUE, factor(.5), matrix(0.5),
"0.5", list(0.5), numeric(0), NA, NaN
)
try(inspect_bfactor_log(mylist[[1]]))
try(inspect_bfactor_log(mylist[[2]]))
try(inspect_bfactor_log(mylist[[3]]))
try(inspect_bfactor_log(mylist[[4]]))
try(inspect_bfactor_log(mylist[[5]]))
try(inspect_bfactor_log(mylist[[6]]))
try(inspect_bfactor_log(mylist[[7]]))
try(inspect_bfactor_log(mylist[[8]]))
try(inspect_bfactor_log(mylist[[9]]))
Validate Bayes factor interpretation scales
Description
inspect_bfactor_scale checks if an object is a character
vector of length 1 that is eligible to represent one of
the Bayes factor interpretation scales available in the pcal package. This
can be useful to validate inputs in user-defined functions.
Usage
inspect_bfactor_scale(x)
Arguments
x |
An arbitrary object. |
Details
inspect_bfactor_scale conducts a series of tests to check if x
is a character vector of length 1 that is eligible to
represent one of the Bayes factor interpretation scales available in the
pcal package. Namely, inspect_bfactor_scale checks if:
-
xisNULLor empty. -
xisNAorNaN. -
xis an atomic vector oflength1 The
typeofxis characterThe value of
xis either "Jeffreys" or "Kass-Raftery" (not case sensitive).
Value
inspect_bfactor_scale does not return any output. There are two
possible scenarios:
The call is silent if
xis a character vector oflength1 that is eligible to represent one of the Bayes factor interpretation scales available in thepcalpackage.An informative error message is thrown otherwise.
See Also
-
bfactor_interpretfor the interpretation of Bayes factors. -
bfactor_log_interpretfor the interpretation of the logarithms of Bayes factors. -
inspect_bfactorto check if an object is a numeric vector of valid Bayes factor values. -
inspect_bfactor_logto check if an object is a numeric vector of valid logarithmic Bayes factor values.
Examples
# Calls that pass silently:
x1 <- "Jeffreys"
x2 <- "jeffreys"
x3 <- "kass-raftery"
x4 <- "Kass-Raftery"
inspect_bfactor_scale(x1)
inspect_bfactor_scale(x2)
inspect_bfactor_scale(x3)
inspect_bfactor_scale(x4)
# Calls that throw informative error messages:
mylist <- list(
NULL, NA, NaN, 10, "Bayes", "Jeff",
"kassraftery", c("jeffreys", "kass-raftery")
)
try(inspect_bfactor_scale(mylist[[1]]))
try(inspect_bfactor_scale(mylist[[2]]))
try(inspect_bfactor_scale(mylist[[3]]))
try(inspect_bfactor_scale(mylist[[4]]))
try(inspect_bfactor_scale(mylist[[5]]))
try(inspect_bfactor_scale(mylist[[6]]))
try(inspect_bfactor_scale(mylist[[7]]))
try(inspect_bfactor_scale(mylist[[8]]))
Validate factor levels
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
inspect_categories(x)
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:
-
xisNULLor empty. -
xis atomic. -
xhas an eligible data type (logical, integer, double, character). There are
NAorNaNvalues inx.There are repeated values in
x.
Value
inspect_categories does not return any output. There are two
possible outcomes:
The call is silent if
xis eligible to be used as the levels of a factor.An informative error message is thrown otherwise.
See Also
-
inspect_data_dichotomousto validate dichotomous data. -
inspect_data_categoricalandinspect_data_cat_as_dichotomto validate categorical data. -
inspect_par_bernoullito validate Bernoulli/Binomial proportions. -
inspect_par_multinomialto validate vectors of Multinomial proportions. -
inspect_characterto validate character vectors. -
inspect_character_matchto validate character vectors with predefined allowed values.
Examples
# 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]]))
Validate character vectors
Description
inspect_character checks if an object is a character vector.
This can be useful to validate inputs in user-defined functions.
Usage
inspect_character(x, allow_nas = TRUE, warning_nas = FALSE)
Arguments
x |
An arbitrary object. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_character conducts a series of tests to check if x is a
character vector. Namely, inspect_character checks if:
-
xisNULLor empty. -
xis an atomic vector. The
typeofxis character.There are
NAorNaNvalues inx.
Value
inspect_character does not return any output. There are three
possible outcomes:
The call is silent if:
-
xis a character vector and there are noNAorNaNvalues inx. -
xis a character vector, there are someNAorNaNvalues inx,allow_nasis set toTRUEandwarning_nasis set toFALSE.
-
An informative warning message is thrown if
xis a character vector, there are someNAorNaNvalues inxand bothallow_nasandwarning_nasare set toTRUE.An informative error message is thrown if:
-
xis not a character vector. -
xis a character vector, there are someNAorNaNvalues inxandallow_nasis set toFALSE.
-
See Also
-
inspect_character_matchto validate character vectors with predefined allowed values. -
inspect_true_or_falseto check if an object is a non-missing logical value.
Examples
# Calls that pass silently:
x1 <- "Kass"
x2 <- c("Kass", "Raftery")
x3 <- c("Kass", "Raftery", NA)
x4 <- letters
inspect_character(x1)
inspect_character(x2)
inspect_character(x3)
inspect_character(x4)
# Call that throws an informative warning message
y <- c("Kass", "Raftery", NA)
try(inspect_character(y, warning_nas = TRUE))
# Calls that throw informative error messages
try(inspect_character(y, allow_nas = FALSE))
mylist <- list(
NULL, character(0), 1,
c(1, 2), factor(c(1, 2)), list(c(1, 2)), NaN, NA
)
try(inspect_character(mylist[[1]]))
try(inspect_character(mylist[[2]]))
try(inspect_character(mylist[[3]]))
try(inspect_character(mylist[[4]]))
try(inspect_character(mylist[[5]]))
try(inspect_character(mylist[[6]]))
try(inspect_character(mylist[[7]]))
try(inspect_character(mylist[[8]]))
Validate character values
Description
inspect_character_match checks if an object is a character
vector of length 1 that belongs to a set of allowed
values. This can be useful to validate inputs in user-defined functions.
Usage
inspect_character_match(x, allowed, case_sensitive = FALSE)
Arguments
x |
An arbitrary object. |
allowed |
A character vector. |
case_sensitive |
A non-missing logical value. |
Details
inspect_character_match conducts a series of tests to check if x
is a character vector of length 1 whose value belongs to
the set of allowed values. Namely, inspect_character_match checks if:
-
xisNULLor empty. -
xis an atomic vector oflength1. The
typeofxis character.-
xisNAorNaN. -
xis one of the allowed values (as specified in theallowedargument).
By default, the comparison of x with allowed is not case sensitive. If
you only want case sensitive matches of x to allowed set case_sensitive
to TRUE.
Value
inspect_character_match does not return any output. There are two
possible outcomes:
The call is silent if
xis a character vector oflength1 whose value belongs to the set of allowed values.An informative error message is thrown otherwise.
See Also
-
inspect_characterto validate character vectors with arbitrary allowed values. -
inspect_true_or_falseto check if an object is a non-missing logical value.
Examples
# Calls that pass silently:
x1 <- "Kass"
x2 <- "kass"
inspect_character_match(x1, allowed = c("Kass", "Raftery"))
inspect_character_match(x2, allowed = c("Kass", "Raftery"))
# Calls that throw informative error messages:
y1 <- "kasss"
y2 <- "kass"
try(inspect_character_match(y1, allowed = c("Kass", "Raftery")))
try(inspect_character_match(y2,
allowed = c("Kass", "Raftery"),
case_sensitive = TRUE
))
mylist <- list(
NULL, character(0), c("abc", "abcd"),
c("abc", "abc"), "ab", list("abc"), factor("abc"), NaN, NA
)
try(inspect_character_match(mylist[[1]], "abc"))
try(inspect_character_match(mylist[[2]], "abc"))
try(inspect_character_match(mylist[[3]], "abc"))
try(inspect_character_match(mylist[[4]], "abc"))
try(inspect_character_match(mylist[[5]], "abc"))
try(inspect_character_match(mylist[[6]], "abc"))
try(inspect_character_match(mylist[[7]], "abc"))
try(inspect_character_match(mylist[[8]], "abc"))
try(inspect_character_match(mylist[[9]], "abc"))
Validate categorical data as dichotomous
Description
inspect_data_cat_as_dichotom checks if an object contains
valid categorical data that is eligible to be used as dichotomous data. This
can be useful to validate inputs in user-defined functions.
Usage
inspect_data_cat_as_dichotom(
data,
success,
allow_nas = TRUE,
warning_nas = FALSE
)
Arguments
data, success |
Arbitrary objects. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_data_cat_as_dichotom conducts a series of tests to check
if data contains valid categorical data that is eligible to be used as
dichotomous data. Namely, inspect_data_cat_as_dichotom checks if:
-
dataandsuccessareNULLor empty. -
dataandsuccessare atomic and have an eligible data type (logical, integer, double, character). -
dataandsuccesshaveNAorNaNvalues. -
successhaslength1. -
successis observed indata.
Value
inspect_data_cat_as_dichotom does not return any output. There are
three possible outcomes:
The call is silent if:
-
datacontains valid categorical data that is eligible to be used as dichotomous data and there are noNAorNaNvalues indata. -
datacontains valid categorical data that is eligible to be used as dichotomous data, there are someNAorNaNvalues indata,allow_nasis set toTRUEandwarning_nasis set toFALSE.
-
An informative warning message is thrown if:
-
datacontains valid categorical data that is eligible to be used as dichotomous data andsuccessis not observed indata. -
datacontains valid categorical data that is eligible to be used as dichotomous data, there areNAorNaNvalues indataand bothallow_nasandwarning_nasare set toTRUE.
-
An informative error message is thrown and the execution is stopped if:
-
datadoes not contain valid categorical data that is eligible to be used as dichotomous data. -
datacontains valid categorical data that is eligible to be used as dichotomous data, there are someNAorNaNvalues indataandallow_nasis set toFALSE.
-
See Also
-
inspect_data_categoricalto validate categorical. -
inspect_par_multinomialto validate vectors of Multinomial proportions. -
inspect_data_dichotomousto validate dichotomous data. -
inspect_par_bernoullito validate Bernoulli/Binomial proportions.
Examples
# Calls that pass silently:
x1 <- c(1, 0, 0, 1, 0)
x2 <- c(FALSE, FALSE, TRUE)
x3 <- c("yes", "no", "yes")
x4 <- factor(c("yes", "no", "yes"))
x5 <- c(1, 0, 0, 1, 0, NA)
inspect_data_cat_as_dichotom(x1, success = 1)
inspect_data_cat_as_dichotom(x2, success = TRUE)
inspect_data_cat_as_dichotom(x3, success = "yes")
inspect_data_cat_as_dichotom(x4, success = "yes")
inspect_data_cat_as_dichotom(x5, success = 1)
# Calls that throw an informative warning message:
y1 <- c(1, 1, NA, 0, 0)
y2 <- c(0, 0)
success <- 1
try(inspect_data_cat_as_dichotom(y1, success = 1, warning_nas = TRUE))
try(inspect_data_cat_as_dichotom(y2, success = success))
# Calls that throw an informative error message:
try(inspect_data_cat_as_dichotom(y1, 1, allow_nas = FALSE))
try(inspect_data_cat_as_dichotom(NULL, 1))
try(inspect_data_cat_as_dichotom(c(1, 0), NULL))
try(inspect_data_cat_as_dichotom(list(1, 0), 1))
try(inspect_data_cat_as_dichotom(c(1, 0), list(1)))
try(inspect_data_cat_as_dichotom(numeric(0), 0))
try(inspect_data_cat_as_dichotom(1, numeric(0)))
try(inspect_data_cat_as_dichotom(NaN, 1))
try(inspect_data_cat_as_dichotom(NA, 1))
try(inspect_data_cat_as_dichotom(c(1, 0), NA))
try(inspect_data_cat_as_dichotom(c(1, 0), NaN))
try(inspect_data_cat_as_dichotom(c(1, 0), 2))
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 |
warning_nas |
Logical value. If |
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:
-
dataisNULLor empty. -
datais atomic and have an eligible data type (logical, integer, double, character). -
datahasNAorNaNvalues.
Value
inspect_data_categorical does not return any output. There are
three possible outcomes:
The call is silent if:
-
datais eligible to have been generated by a Multinomial distribution and there are noNAorNaNvalues indata. -
datais eligible to have been generated by a Multinomial distribution, there are someNAorNaNvalues indataandwarning_nasis set toFALSE.
-
An informative warning message is thrown if:
datais eligible to have been generated by a Multinomial distribution, there are someNAorNaNvalues indataandwarning_nasis set toTRUE.An informative error message is thrown and the execution is stopped if:
-
datais not eligible to have been generated by a Multinomial distribution. -
datais eligible to have been generated by a Multinomial distribution, there are someNAorNaNvalues indataandallow_nasis set toTRUE.
-
See Also
-
inspect_data_cat_as_dichotomto validate categorical data as dichotomous. -
inspect_par_multinomialto validate vectors of Multinomial proportions. -
inspect_data_dichotomousto validate dichotomous data. -
inspect_par_bernoullito validate Bernoulli/Binomial proportions.
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))
Validate dichotomous data
Description
inspect_data_dichotomous checks if an object contains data
that is eligible to have been generated by a series of Bernoulli trials. This
can be useful to validate inputs in user-defined functions.
Usage
inspect_data_dichotomous(data, success, allow_nas = TRUE, warning_nas = FALSE)
Arguments
data, success |
Arbitrary objects. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_data_dichotomous conducts a series of tests to check if
data is eligible to have been generated by a series of Bernoulli trials.
Namely, inspect_data_dichotomous checks if:
-
dataandsuccessareNULLor empty. -
dataandsuccessare atomic and have an eligible data type (logical, integer, double, character). -
dataandsuccesshaveNAorNaNvalues. The number of unique values in
dataandsuccessare adequate.-
successhaslength1. -
successis observed indata.
Value
inspect_data_dichotomous does not return any output. There are
three possible outcomes:
The call is silent if:
-
datais eligible to have been generated by a series of Bernoulli trials and there are noNAorNaNvalues indata. -
datais eligible to have been generated by a series of Bernoulli trials, there are someNAorNaNvalues indata,allow_nasis set toTRUEandwarning_nasis set toFALSE.
-
An informative warning message is thrown if:
-
datais eligible to have been generated by a series of Bernoulli trials andsuccessis not observed indata. -
datais eligible to have been generated by a series of Bernoulli trials, there areNAorNaNvalues indataand bothallow_nasandwarning_nasare set toTRUE.
-
An informative error message is thrown and the execution is stopped if:
-
datais not eligible to have been generated by a series of Bernoulli trials. -
datais eligible to have been generated by a series of Bernoulli trials, there are someNAorNaNvalues indataandallow_nasis set toFALSE.
-
See Also
-
inspect_par_bernoullito validate Bernoulli/Binomial proportions. -
inspect_data_categoricalandinspect_data_cat_as_dichotomto validate categorical data. -
inspect_par_multinomialto validate vectors of Multinomial proportions.
Examples
# Calls that pass silently:
x1 <- c(1, 0, 0, 1, 0)
x2 <- c(FALSE, FALSE, TRUE)
x3 <- c("yes", "no", "yes")
x4 <- factor(c("yes", "no", "yes"))
x5 <- c(1, 0, 0, 1, 0, NA)
inspect_data_dichotomous(x1, success = 1)
inspect_data_dichotomous(x2, success = TRUE)
inspect_data_dichotomous(x3, success = "yes")
inspect_data_dichotomous(x4, success = "yes")
inspect_data_dichotomous(x5, success = 1)
# Calls that throw an informative warning message:
y1 <- c(1, 1, NA, 0, 0)
y2 <- c(0, 0)
success <- 1
try(inspect_data_dichotomous(y1, success = 1, warning_nas = TRUE))
try(inspect_data_dichotomous(y2, success = success))
# Calls that throw an informative error message:
try(inspect_data_dichotomous(NULL, 1))
try(inspect_data_dichotomous(c(1, 0), NULL))
try(inspect_data_dichotomous(list(1, 0), 1))
try(inspect_data_dichotomous(c(1, 0), list(1)))
try(inspect_data_dichotomous(numeric(0), 0))
try(inspect_data_dichotomous(1, numeric(0)))
try(inspect_data_dichotomous(NaN, 1))
try(inspect_data_dichotomous(NA, 1))
try(inspect_data_dichotomous(c(1, 0), NA))
try(inspect_data_dichotomous(c(1, 0), NaN))
try(inspect_data_dichotomous(c(1, 0), 2))
Validate logarithmic bases
Description
inspect_log_base checks if an object is a valid a logarithmic
base. This can be useful to validate inputs in user-defined functions.
Usage
inspect_log_base(x)
Arguments
x |
An arbitrary object. |
Details
inspect_log_base conducts a series of tests to check if x is a
valid logarithmic base. Namely, inspect_log_base checks if:
-
xisNULLor empty. -
xis an atomic vector oflength1. -
xis numeric. -
xisNAorNaN. -
xis positive.
Value
inspect_log_base does not return any output. There are two possible
outcomes:
The call is silent if
xis a numeric vector oflength1 that is a valid logarithmic base.An informative error message is thrown otherwise.
See Also
-
bfactor_log_interpretfor the interpretation of the logarithms of Bayes factors. -
inspect_bfactor_logto check if an object is a numeric vector of valid logarithmic Bayes factor values.
Examples
# Calls that pass silently:
x1 <- 10
x2 <- exp(1)
x3 <- 0.5
inspect_log_base(x1)
inspect_log_base(x2)
inspect_log_base(x3)
# Calls that throw informative error messages:
mylist <- list(
NULL, numeric(0), TRUE, factor(10),
list(10), matrix(10), NaN, NA, -1, 0
)
try(inspect_log_base(mylist[[1]]))
try(inspect_log_base(mylist[[2]]))
try(inspect_log_base(mylist[[3]]))
try(inspect_log_base(mylist[[4]]))
try(inspect_log_base(mylist[[5]]))
try(inspect_log_base(mylist[[6]]))
try(inspect_log_base(mylist[[7]]))
try(inspect_log_base(mylist[[8]]))
try(inspect_log_base(mylist[[9]]))
try(inspect_log_base(mylist[[10]]))
Validate parameters for the Bernoulli/Binomial distributions
Description
inspect_par_bernoulli checks if an object is an eligible
Bernoulli/Binomial proportion. This can be useful to validate inputs,
intermediate calculations or outputs in user-defined functions.
Usage
inspect_par_bernoulli(x)
Arguments
x |
An arbitrary object. |
Details
inspect_par_bernoulli conducts a series of tests to check if x
is an eligible Bernoulli/Binomial proportion. Namely, inspect_par_bernoulli
checks if:
-
xisNULLor empty. -
xis an atomic vector -
xis numeric -
xhaslength1 -
xisNAorNaN. -
xis in the (0, 1) interval.
Value
inspect_par_bernoulli does not return any output. There are two
possible outcomes:
The call is silent if
xis an eligible Bernoulli/Binomial proportion.An informative error message is thrown otherwise.
See Also
-
inspect_par_multinomialto validate parameters for the Multinomial distribution. -
inspect_par_betato validate parameters for the Beta distribution. -
inspect_par_dirichletto validate parameters for the Dirichlet distribution. -
inspect_par_haldaneto validate parameters for the Haldane distribution. -
inspect_data_dichotomousto validate dichotomous data. -
inspect_probto check if an object is a numeric vector of valid probability values.
Examples
# Calls that pass silently:
x <- 0.5
inspect_par_bernoulli(x)
inspect_par_bernoulli(0.1)
# Calls that throw an informative error message:
mylist <- list(
NULL, TRUE, factor(.5), matrix(0.5), "0.5",
list(0.5), NA, NaN, numeric(0), c(0.1, 0.5), -0.5, 1.1
)
try(inspect_par_bernoulli(mylist[[1]]))
try(inspect_par_bernoulli(mylist[[2]]))
try(inspect_par_bernoulli(mylist[[3]]))
try(inspect_par_bernoulli(mylist[[4]]))
try(inspect_par_bernoulli(mylist[[5]]))
try(inspect_par_bernoulli(mylist[[6]]))
try(inspect_par_bernoulli(mylist[[7]]))
try(inspect_par_bernoulli(mylist[[8]]))
try(inspect_par_bernoulli(mylist[[9]]))
try(inspect_par_bernoulli(mylist[[10]]))
try(inspect_par_bernoulli(mylist[[11]]))
try(inspect_par_bernoulli(mylist[[12]]))
Validate parameters for the Beta distribution
Description
inspect_par_beta checks if an object is an eligible vector of
parameters for the Beta distribution. This can be useful to validate inputs,
intermediate calculations or outputs in user-defined functions.
Usage
inspect_par_beta(x)
Arguments
x |
An arbitrary object. |
Details
inspect_par_beta conducts a series of tests to check if x is an
eligible vector of parameters for the Beta distribution. Namely,
inspect_par_beta checks if:
-
xisNULLor empty. -
xis an atomic vector -
xis numeric -
xhaslength2 -
xhasNAorNaNvalues. All elements of
xare positive.
Value
inspect_par_beta does not return any output. There are two possible
outcomes:
The call is silent if
xis an eligible vector of parameters for the Beta distribution.An informative error message is thrown otherwise.
See Also
-
inspect_par_bernoullito validate parameters for the Bernoulli/Binomial distribution. -
inspect_par_multinomialto validate parameters for the Multinomial distribution. -
inspect_par_dirichletto validate parameters for the Dirichlet distribution. -
inspect_par_haldaneto validate parameters for the Haldane distribution.
Examples
# Calls that pass silently:
x1 <- c(1, 1)
x2 <- c(2, 5)
inspect_par_beta(x1)
inspect_par_beta(x2)
# Calls that throw an informative error message:
mylist <- list(
NULL, 1, factor(1, 1),
matrix(c(1, 1)), c("1", "1"), list(1, 1), c(1, NA),
c(1, NaN), c(TRUE, FALSE), numeric(0), c(-1, 1)
)
try(inspect_par_beta(mylist[[1]]))
try(inspect_par_beta(mylist[[2]]))
try(inspect_par_beta(mylist[[3]]))
try(inspect_par_beta(mylist[[4]]))
try(inspect_par_beta(mylist[[5]]))
try(inspect_par_beta(mylist[[6]]))
try(inspect_par_beta(mylist[[7]]))
try(inspect_par_beta(mylist[[8]]))
try(inspect_par_beta(mylist[[9]]))
try(inspect_par_beta(mylist[[10]]))
try(inspect_par_beta(mylist[[11]]))
Validate parameters for the Dirichlet distribution
Description
inspect_par_dirichlet checks if an object is an eligible
vector of parameters for the Dirichlet distribution. This can be useful to
validate inputs, intermediate calculations or outputs in user-defined
functions.
Usage
inspect_par_dirichlet(x)
Arguments
x |
An arbitrary object. |
Details
inspect_par_dirichlet conducts a series of tests to check if x
is an eligible vector of parameters for the Dirichlet distribution. Namely,
inspect_par_dirichlet checks if:
-
xisNULLor empty. -
xis an atomic vector -
xis numeric -
xhasNAorNaNvalues. All elements of
xare positive.
Value
inspect_par_dirichlet does not return any output. There are two
possible outcomes:
The call is silent if
xis an eligible vector of parameters for the Dirichlet distribution.An informative error message is thrown otherwise.
See Also
-
inspect_par_bernoullito validate parameters for the Bernoulli/Binomial distribution. -
inspect_par_multinomialto validate parameters for the Multinomial distribution. -
inspect_par_betato validate parameters for the Beta distribution. -
inspect_par_haldaneto validate parameters for the Haldane distribution.
Examples
# Calls that pass silently:
x1 <- c(1, 1, 1)
x2 <- c(2, 5)
inspect_par_dirichlet(x1)
inspect_par_dirichlet(x2)
# Calls that throw an informative error message:
mylist <- list(
NULL, factor(1, 1, 1),
matrix(c(1, 1, 1)), c("1", "1", "1"), list(1, 1, 1), c(1, NA),
c(1, NaN, 1), c(TRUE, FALSE), numeric(0), c(-1, 1, 1)
)
try(inspect_par_dirichlet(mylist[[1]]))
try(inspect_par_dirichlet(mylist[[2]]))
try(inspect_par_dirichlet(mylist[[3]]))
try(inspect_par_dirichlet(mylist[[4]]))
try(inspect_par_dirichlet(mylist[[5]]))
try(inspect_par_dirichlet(mylist[[6]]))
try(inspect_par_dirichlet(mylist[[7]]))
try(inspect_par_dirichlet(mylist[[8]]))
try(inspect_par_dirichlet(mylist[[9]]))
try(inspect_par_dirichlet(mylist[[10]]))
Validate parameters for the Haldane distribution
Description
inspect_par_haldane checks if an object is an eligible vector
of parameters for the Haldane distribution. This can be useful to validate
inputs, intermediate calculations or outputs in user-defined functions.
Usage
inspect_par_haldane(x)
Arguments
x |
An arbitrary object. |
Details
inspect_par_haldane conducts a series of tests to check if x is
an eligible vector of parameters for the Haldane distribution. Namely,
inspect_par_haldane checks if:
-
xisNULLor empty. -
xis an atomic vector -
xis numeric -
xhasNAorNaNvalues. All elements of
xequal to 0.
Value
inspect_par_haldane does not return any output. There are two
possible outcomes:
The call is silent if
xis an eligible vector of parameters for the Haldane distribution.An informative error message is thrown otherwise.
See Also
-
inspect_par_bernoullito validate parameters for the Bernoulli/Binomial distribution. -
inspect_par_multinomialto validate parameters for the Multinomial distribution. -
inspect_par_betato validate parameters for the Beta distribution. -
inspect_par_dirichletto validate parameters for the Dirichlet distribution.
Examples
# Calls that pass silently:
x1 <- c(0, 0, 0)
x2 <- c(0, 0)
inspect_par_haldane(x1)
inspect_par_haldane(x2)
# Calls that throw an informative error message:
mylist <- list(
NULL, factor(0, 0, 0),
matrix(c(0, 0, 0)), c("0", "0", "0"), list(0, 0, 0), c(0, NA),
c(0, NaN, 0), c(TRUE, FALSE), numeric(0), c(1, 0, 0)
)
try(inspect_par_haldane(mylist[[1]]))
try(inspect_par_haldane(mylist[[2]]))
try(inspect_par_haldane(mylist[[3]]))
try(inspect_par_haldane(mylist[[4]]))
try(inspect_par_haldane(mylist[[5]]))
try(inspect_par_haldane(mylist[[6]]))
try(inspect_par_haldane(mylist[[7]]))
try(inspect_par_haldane(mylist[[8]]))
try(inspect_par_haldane(mylist[[9]]))
try(inspect_par_haldane(mylist[[10]]))
Validate parameters for the Multinomial distribution
Description
inspect_par_multinomial checks if an object is an eligible
vector of Multinomial proportions. This can be useful to validate inputs,
intermediate calculations or outputs in user-defined functions.
Usage
inspect_par_multinomial(x)
Arguments
x |
An arbitrary object. |
Details
inspect_par_multinomial conducts a series of tests to check if
x is an eligible vector of Multinomial proportions. Namely,
inspect_par_multinomial checks if:
-
xisNULLor empty. -
xis an atomic vector -
xis numeric -
xhasNAorNaNvalues. All elements of
xare in the (0, 1) interval.-
xsums to 1.
Value
inspect_par_multinomial does not return any output.
There are two possible outcomes:
The call is silent if
xis an eligible vector of Multinomial proportions.An informative error message is thrown otherwise.
See Also
-
inspect_par_bernoullito validate parameters for the Bernoulli/Binomial distribution. -
inspect_par_betato validate parameters for the Beta distribution. -
inspect_par_dirichletto validate parameters for the Dirichlet distribution. -
inspect_par_haldaneto validate parameters for the Haldane distribution. -
inspect_data_categoricalandinspect_data_cat_as_dichotomto validate categorical data. -
inspect_probto check if an object is a numeric vector of valid probability values.
Examples
# Calls that pass silently:
x1 <- c(0.5, 0.5)
x2 <- rep(1 / 5, 5)
inspect_par_multinomial(x1)
inspect_par_multinomial(x2)
# Calls that throw an informative error message:
mylist <- list(
NULL, TRUE, factor(0.5, 0.5),
matrix(c(0.5, 0.5)), c("0.5", "0.5"), list(0.5, 0.5),
c(0.9, NA), c(0.9, NaN), numeric(0), NA, c(0.9, 0.6), c(-0.1, 0.9)
)
try(inspect_par_multinomial(mylist[[1]]))
try(inspect_par_multinomial(mylist[[2]]))
try(inspect_par_multinomial(mylist[[3]]))
try(inspect_par_multinomial(mylist[[4]]))
try(inspect_par_multinomial(mylist[[5]]))
try(inspect_par_multinomial(mylist[[6]]))
try(inspect_par_multinomial(mylist[[7]]))
try(inspect_par_multinomial(mylist[[8]]))
try(inspect_par_multinomial(mylist[[9]]))
try(inspect_par_multinomial(mylist[[10]]))
try(inspect_par_multinomial(mylist[[11]]))
try(inspect_par_multinomial(mylist[[12]]))
Validate vectors of probabilities
Description
inspect_prob checks if an object is a numeric vector of valid
probability values. This can be useful to validate inputs, intermediate
calculations or outputs in user-defined functions.
Usage
inspect_prob(x, allow_nas = TRUE, warning_nas = TRUE)
Arguments
x |
An arbitrary object. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_prob conducts a series of tests to check if x is a
numeric vector of valid probability values. Namely, inspect_prob checks if:
-
xisNULLor empty. -
xis an atomic vector. -
xis numeric. -
xhasNAorNaNvalues. The values of
xare in the [0, 1] interval.
Value
inspect_prob does not return any output. There are three possible
outcomes:
The call is silent if:
-
xis a numeric vector of valid probability values and there are noNAorNaNvalues inx. -
xis a numeric vector of valid probability values, there are someNAorNaNvalues inx,allow_nasis set toTRUEandwarning_nasis set toFALSE.
-
An informative warning message is thrown if
xis a numeric vector of valid probability values, there are someNAorNaNvalues inxand bothallow_nasandwarning_nasare set toTRUE.An informative error message is thrown and the execution is stopped if:
-
xis not a numeric vector of valid probability values. -
xis a numeric vector of valid probability values, there are someNAorNaNvalues inxandallow_nasis set toFALSE.
-
See Also
-
inspect_par_bernoullito check if an object is a valid Bernoulli/Binomial proportion. -
inspect_par_multinomialto check if an object is a numeric vector of valid Multinomial proportions.
Examples
# Calls that pass silently:
x1 <- c(0.1, 0.2, 0.3, 0.4, 0.5)
x2 <- c(0.1, 0.2, 0.3, 0.4, 0.5, NA)
inspect_prob(x1)
inspect_prob(x2, warning_nas = FALSE)
inspect_prob(x2, allow_nas = TRUE, warning_nas = FALSE)
# Calls that throw an informative warning message:
y <- c(0.1, 0.2, NA, 0.4, 0.5)
try(inspect_prob(y))
try(inspect_prob(y, allow_nas = TRUE))
try(inspect_prob(y, allow_nas = TRUE, warning_nas = TRUE))
# Calls that throw an informative error message:
z1 <- c(-0.9, 0, 0.1, 0.2, 0.3, 0.4, 0.5)
try(inspect_prob(z1))
z2 <- c(NA, 0, 0.1, 0.2, 0.3, 0.4, 0.5)
try(inspect_prob(z2, allow_nas = FALSE))
mylist <- list(
NULL, TRUE, factor(.5), matrix(0.5),
"0.5", list(0.5), NA, NaN, numeric(0), 1.1, -0.5
)
try(inspect_prob(mylist[[1]]))
try(inspect_prob(mylist[[2]]))
try(inspect_prob(mylist[[3]]))
try(inspect_prob(mylist[[4]]))
try(inspect_prob(mylist[[5]]))
try(inspect_prob(mylist[[6]]))
try(inspect_prob(mylist[[7]]))
try(inspect_prob(mylist[[8]]))
try(inspect_prob(mylist[[9]]))
try(inspect_prob(mylist[[10]]))
try(inspect_prob(mylist[[11]]))
Validate non-missing logical values
Description
inspect_true_or_false checks if an object is a non-missing
logical vector of length 1. This can be useful to
validate inputs in user-defined functions.
Usage
inspect_true_or_false(x)
Arguments
x |
An arbitrary object. |
Details
inspect_true_or_false conducts a series of tests to check if x
is a non-missing logical vector of length 1. Namely,
inspect_true_or_false checks if:
Value
inspect_true_or_false does not return any output. There are two
possible scenarios:
The call is silent if
xis a non-missing logical vector oflength1.An informative error message is thrown otherwise.
See Also
-
inspect_characterto validate character vectors. -
inspect_character_matchto validate character vectors with predefined allowed values.
Examples
# Calls that pass silently:
x <- TRUE
y <- FALSE
inspect_true_or_false(x)
inspect_true_or_false(y)
# Calls that throw informative error messages:
mylist <- list(NULL, NA, NaN, 1, 0, "TRUE")
try(inspect_true_or_false(mylist[[1]]))
try(inspect_true_or_false(mylist[[2]]))
try(inspect_true_or_false(mylist[[3]]))
try(inspect_true_or_false(mylist[[4]]))
try(inspect_true_or_false(mylist[[5]]))
try(inspect_true_or_false(mylist[[6]]))