R/is_one_empty_string.R

Defines functions is_one_empty_string

Documented in is_one_empty_string

#' Determine if an object is one empty string
#' @param x the object that may be one string that may be empty
#' @return TRUE is `x` is one string that is empty
#' @examples
#' # TRUE
#' is_one_empty_string("")
#'
#' # FALSE
#' is_one_empty_string("3.14")
#' is_one_empty_string(c("", ""))
#' is_one_empty_string(42)
#' is_one_empty_string("nonsense")
#' @author Richèl J.C. Bilderbeek
#' @export
is_one_empty_string <- function(x) {
  if (length(x) != 1) return(FALSE)
  if (!is.character(x)) return(FALSE)
  nchar(x) == 0
}

Try the beautier package in your browser

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

beautier documentation built on Nov. 2, 2023, 5:08 p.m.