]>
nmode's Git Repositories - Rnaught/blob - R/util.R
1 #' Case Counts Validation
3 #' This is an internal function called by the estimators. It validates the
4 #' supplied case counts by ensuring it is a vector of integers of length at
5 #' least `min_length` with entries greater than or equal to `min_count`.
6 #' Execution is halted if these requirements are not satisfied.
8 #' @param cases The case counts to be validated.
9 #' @param min_length The minimum length of the vector of case counts.
10 #' @param min_count The minimum value of the case count vector's entries.
13 validate_cases
<- function(cases
, min_length
, min_count
) {
14 if (!is.vector(cases
) || !is.numeric(cases
) || any(floor(cases
) != cases
)) {
15 stop("Case counts must be a vector of integers.", call.
= FALSE)
17 if (length(cases
) < min_length
) {
18 stop(paste("Case counts must have at least", min_length
, "entries."),
22 if (any(cases
< min_count
)) {
23 stop(paste0("Case counts cannot be less than ", min_count
, "."),
29 #' Real Number Testing
31 #' This is an internal function which checks whether the given argument is a
34 #' @param x The argument to test for being a real number.
36 #' @return `TRUE` if the argument is a real number, `FALSE` otherwise.
39 is_real
<- function(x
) {
40 is.vector(x
) && is.numeric(x
) && length(x
) == 1
45 #' This is an internal function which checks whether the given argument is an
48 #' @param n The argument to test for being an integer.
50 #' @return `TRUE` if the argument is an integer, `FALSE` otherwise.
53 is_integer
<- function(n
) {
54 is_real(n
) && floor(n
) == n