R/assertions.R

Defines functions is_named is_tree_style is_count is_col is_padding_or_margin is_border_style is_flag is_string

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

is_flag <- function(x) {
  is.logical(x) && length(x) == 1 && !is.na(x)
}

is_border_style <- function(x) {
  is_string(x) && x %in% rownames(box_styles())
}

is_padding_or_margin <- function(x) {
  is.numeric(x) && length(x) %in% c(1, 4) && all(!is.na(x)) &&
    all(as.integer(x) == x)
}

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

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

is_tree_style <- function(x) {
  is.list(x) &&
    length(x) == 4 &&
    !is.null(names(x)) &&
    all(sort(names(x)) == sort(c("h", "v", "l", "j"))) &&
    all(sapply(x, is_string))
}

is_named <- function(x) {
  !is.null(names(x))
}

Try the cli package in your browser

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

cli documentation built on March 31, 2023, 9:04 p.m.