R/envvar.R

Defines functions get_envvar using_envvar

Documented in using_envvar

#' Determine whether an environment variable is being used
#'
#' @param x Environment variable
#' @param value Optional value to compare against
#'
#' @return A logical value
#' @export
#'
#' @examples
#' using_envvar("NOT_CRAN")
#'
#' using_envvar("CI", "true")
using_envvar <- function(x, value = NULL) {
  assert_string(x)
  assert_string(value, null_ok = TRUE)

  curr <- get_envvar(x)
  if (is.null(value)) {
    !is.na(curr)
  } else {
    assert_string(value)
    identical(curr, value)
  }
}

get_envvar <- function(x) {
  Sys.getenv(x, unset = NA_character_)
}

Try the ami package in your browser

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

ami documentation built on April 4, 2025, 2:39 a.m.