useBasiliskEnv {basilisk} | R Documentation |
Use basilisk environments for isolated execution of Python code with appropriate versions of all Python packages.
useBasiliskEnv(envpath, dry = FALSE, required = TRUE)
envpath |
String containing the path to the basilisk environment to use. |
dry |
Logical scalar indicating whether only the directory should be returned without loading the environment. |
required |
Logical scalar indicating whether an error should be raised if the requested environment cannot be found. |
It is unlikely that developers should ever need to call useBasiliskEnv
directly.
Rather, this interaction should be automatically handled by basiliskStart
.
Direct use of this function with dry=FALSE
will modify some environment variables for the current R session:
The "PYTHONPATH"
environment variable is unset.
This is a deliberate choice to avoid compromising the version guarantees if import
is allowed to search other locations beyond the specified basilisk environment.
The "RETICULATE_PYTHON"
environment variable is unset.
This would otherwise override any choice of Python, including explicit specification via use_condaenv
!
Certain conda-related variables are modified to mimic activation of the desired conda environment in envpath
.
Actual activation seems to require modification of various files (e.g., .bashrc
) which is undesirable.
If dry=TRUE
, no environment variables are modified.
Similarly, if the loading of the environment in envpath
was not successful (i.e., loaded
is FALSE
), no environment variables are modified and previous
is an empty list.
Further note that basiliskStop
will restore these environment variables to their state prior to running basiliskStart
.
The function will attempt to load the specified basilisk environment into the R session, possibly with the modification of some environment variables (see Details).
It returns a list containing:
loaded
, a logical scalar indicating whether the Python version in envpath
was correctly loaded.
previous
, a list of environment variables with their values prior to running this function.
If dry=TRUE
, only the logical scalar in loaded
is returned directly.
Aaron Lun
basiliskStart
, for how these basilisk environments should be used.
# This may return TRUE or FALSE, depending on the available Python. tmploc <- file.path(tempdir(), "my_package_B") setupBasiliskEnv(tmploc, c('pandas==0.25.1', "python-dateutil=2.8.0", "pytz=2019.3")) useBasiliskEnv(tmploc, required=FALSE) # This will return FALSE, as the available Python is already set. baseloc <- basilisk.utils::getBasiliskDir() useBasiliskEnv(baseloc, required=FALSE)