Skip to contents

Marks a directory as a Conda environment to run commands from. Use it for an environment that condathis did not create, such as one created by another user, or by conda, mamba or micromamba directly. Pass the result as env_name to run(), run_bin(), run_pipeline() or run_step().

Usage

env_path(path)

Arguments

path

Character string with the path of the environment directory (the prefix), absolute or relative to the working directory. env_path() expands a leading ~. A value that is not a single, non-empty string aborts with class condathis_env_path_invalid_path (also condathis_invalid_path).

Value

An object of class condathis_env_path, holding the absolute path.

Details

Environments given by path are read-only for condathis: only the run() family accepts them. create_env(), install_packages(), remove_env(), validate_env(), env_exists(), list_packages() and get_env_dir() reject them with an error of class condathis_env_path_read_only (also condathis_invalid_env_name), and list_envs() does not list them.

Commands in an environment given by path run with the environment's own activation. They need a backend that can activate an environment given by its directory. The micromamba backend can. With method = "auto", the first such backend in the order of the option condathis.backend_priority runs it, micromamba by default. A method that names a backend that cannot aborts with class condathis_env_path_unsupported_method (also condathis_backend_unsupported).

env_path() makes path absolute against the working directory at the time of the call, so a later setwd() does not change which environment it refers to. The function that gets the path checks it when the command runs, and honors its error argument. The directory must exist and contain a conda-meta directory. Otherwise, error = "cancel" aborts with class condathis_env_path_not_found or condathis_env_path_not_conda_env (both also condathis_env_not_found).

Prefer environment names in scripts that other people run: a path is specific to one machine.

Examples

condathis::env_path("/opt/conda/envs/shared-tools")
#> <env_path> /opt/conda/envs/shared-tools

if (FALSE) { # \dontrun{
condathis::with_sandbox_dir({
  # An environment created outside condathis, here with micromamba
  # itself, in a directory of our choosing. `--no-rc` and `--no-env`
  # make micromamba ignore your own Conda settings, as condathis does.
  channel <- system.file(
    "extdata", "polyglot-channel",
    package = "condathis"
  )
  prefix <- file.path(tempdir(), "my-prefix-env")
  condathis::install_micromamba()
  processx::run(
    condathis::micromamba_bin_path(),
    c(
      "create", "-y", "--no-rc", "--no-env",
      "-r", file.path(tempdir(), "mamba-root"),
      "-p", prefix, "-c", channel, "--override-channels", "polyglot"
    )
  )

  condathis::run("polyglot", env_name = condathis::env_path(prefix))

  # `with_sandbox_dir()` does not change `tempdir()`: clean up.
  unlink(c(prefix, file.path(tempdir(), "mamba-root")), recursive = TRUE)
})
} # }