R/helpers.R

Defines functions factor2level rowAll rowAny is.empty.lst is.empty.int is.empty.num is.empty.chr is.empty

# is empty
#' @export
is.empty     <- function(x) if (length(x)) lengths(x) == 0 else TRUE
is.empty.chr <- function(x) identical(x, character(0))
is.empty.num <- function(x) identical(x, numeric(0))
is.empty.int <- function(x) identical(x, integer(0))
is.empty.lst <- function(x) identical(x, list())

# others
#' @export
rowAny <- function(x) rowSums(x) > 0
#' @export
rowAll <- function(x) rowSums(x) == ncol(x)

#' @export
factor2level <- function(x) {
  vapply(x, \(y) which(levels(x) == y), 0)
}
salix-d/salix_miscFuns documentation built on Aug. 14, 2024, 7:45 p.m.