R/has-names.R

Defines functions has_names

Documented in has_names

#' Check if all elements of an object are named
#'
#' Check if all elements of an object have non-empty names.
#'
#' @param x `[any]`
#'
#'   An object.
#'
#' @returns A `logical(1)`.
#'
#' @details This function first checks if the underlying `names` attribute of
#'   `x` is `NULL`. If it is not, then it checks if all its elements are
#'   non-empty strings (`character(1)` values __not__ equal to `""`).
#'
#' @examples
#' x <- c(a = 1, b = 2, 3)
#' y <- c(a = 1, b = 2, c = 3)
#'
#' has_names(x) # FALSE
#' has_names(y) # TRUE
#'
#' @export
has_names <- function(x)
{
    nms <- names(x)
    return(!is_nul(nms) && all(nzchar(nms)))
}
jeanmathieupotvin/dotprofile documentation built on Dec. 20, 2021, 10:08 p.m.