R/assertions.R

Defines functions is_count_or_null is_count is_string_or_null is_string is_character_or_null is_character

is_character <- function(x) {
  is.character(x) && !anyNA(x) && length(x) > 0L
}

is_character_or_null <- function(x) {
  is.null(x) || is_character(x)
}

is_string <- function(x) {
  is.character(x) && length(x) == 1L && !is.na(x)
}

is_string_or_null <- function(x) {
  is.null(x) || is_string(x)
}

is_count <- function(x) {
  is.numeric(x) && length(x) == 1L && !is.na(x) &&
    as.integer(x) == x && x > 0L
}

is_count_or_null <- function(x) {
  is.null(x) || is_count(x)
}

Try the bbk package in your browser

Any scripts or data that you put into this service are public.

bbk documentation built on Sept. 11, 2024, 8:02 p.m.