R/check_boolean.R

Defines functions check_is_scalar_boolean check_is_boolean

Documented in check_is_boolean check_is_scalar_boolean

#' Help function checking if a variable is a vector of booleans.
#'
#' @inherit .check_params params author return seealso
#'
#' @keywords internal
#'
check_is_boolean <- function(x,
                             error = FALSE) {

  # check if input is a boolean vector
  if (!rlang::is_logical(x)
      || any(rlang::are_na(x))) {

    if (error == TRUE) {

      cli::cli_abort( # nolint: return_linter
        c(
          "x" = "{.arg {rlang::caller_arg(x)}} must be a boolean vector!"
        ),
        call = rlang::caller_env(),
        wrap = FALSE
      )

    } else {

      return(FALSE)

    }

  } else {

    return(TRUE)

  }

}

#' Help function checking if a variable is a scalar boolean.
#'
#' @inherit .check_params params author return seealso
#'
#' @keywords internal
#'
check_is_scalar_boolean <- function(x,
                                    error = FALSE) {

  # check if input is a boolean vector of length 1
  if (!rlang::is_scalar_logical(x)
      || rlang::is_na(x)) {

    if (error == TRUE) {

      cli::cli_abort( # nolint: return_linter
        c(
          "x" = "{.arg {rlang::caller_arg(x)}} must be a scalar boolean!"
        ),
        call = rlang::caller_env(),
        wrap = FALSE
      )

    } else {

      return(FALSE)

    }

  } else {

    return(TRUE)

  }

}

Try the OlinkAnalyze package in your browser

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

OlinkAnalyze documentation built on June 24, 2026, 1:06 a.m.