Skip to contents

Is conda enabled (active) in the current R session?

Usage

isCondaEnabled(ignoreBase = TRUE)

Arguments

ignoreBase

logical(1). If TRUE, don't consider conda to be "active" if only the base environment is loaded. This is useful to avoid some false-positive situations when handling the main conda activate script in shell sessions.

Value

TRUE on success; FALSE on failure, with cause set.

Details

This checks CONDA_DEFAULT_ENV and CONDA_SHLVL system environment variables internally.

Note

Updated 2021-08-19.

Examples

vars <- c("CONDA_DEFAULT_ENV", "CONDA_SHLVL")
Sys.unsetenv(vars)

## TRUE ====
Sys.setenv(
    "CONDA_DEFAULT_ENV" = "test",
    "CONDA_SHLVL" = "2"
)
isCondaEnabled()
#> [1] TRUE
Sys.unsetenv(vars)

Sys.setenv(
    "CONDA_DEFAULT_ENV" = "base",
    "CONDA_SHLVL" = "1"
)
isCondaEnabled(ignoreBase = FALSE)
#> [1] TRUE
Sys.unsetenv(vars)

## FALSE ====
isCondaEnabled()
#> [1] FALSE

Sys.setenv(
    "CONDA_DEFAULT_ENV" = "base",
    "CONDA_SHLVL" = "1"
)
isCondaEnabled(ignoreBase = TRUE)
#> [1] FALSE
Sys.unsetenv(vars)