activateEnvironment: Activate a Conda environment

View source: R/activateEnvironment.R

activateEnvironmentR Documentation

Activate a Conda environment

Description

Mimic the (de)activation of a Conda environment by modifying environment variables in the current R process.

Usage

activateEnvironment(envpath = NULL, loc = getCondaDir())

deactivateEnvironment(listing)

Arguments

envpath

String containing the path to the Conda environment to activate. If NULL, the base Conda instance at getCondaDir() is activated.

loc

String containing the path to the root of a conda instance.

listing

Named list of strings containing name:value pairs for environment variables, typically the output of activateEnvironment.

Details

Conda environments generally need to be activated to function properly. This is especially relevant on Windows where the "PATH" variable needs to be modified for the DLL search. The .activateEnvironment function mimics the effect of activation by modifying environment variables in the current R session. This can be reversed by .deactivateEnvironment once the Conda environment is no longer in use.

The .activateEnvironment function will also unset a few bothersome environment variables:

  • "PYTHONPATH": to avoid compromising the version guarantees if reticulate's import is allowed to search other locations beyond the specified Conda environment.

  • "PYTHONNOUSERSITE": similarly, to avoid searching the user's site libraries.

  • "RETICULATE_PYTHON": this would otherwise override any choice of Python, even after explicit specification via reticulate's use_Condaenv!

  • "RETICULATE_PYTHON_ENV": for similar reasons.

Value

activateEnvironment will modify environment variables to mimic activation of the Conda environment. It returns a named list of the previous values of all variables modified in this manner. (NA values indicate that the corresponding variable was not previously set.)

deactivateEnvironment restores the environment variables to their pre-activation state. It returns NULL invisibly.

Author(s)

Aaron Lun

Examples

# We can't actually run activateEnvironment() here, as it 
# either relies on basilisk already being installed or
# it has a hard-coded path to the basilisk system dir.
print("dummy test to pass BiocCheck")


LTLA/basilisk.utils documentation built on June 26, 2022, 4:06 a.m.