Creates a Conda environment from package specs or from an environment
file given by env_definition(). With overwrite = FALSE (the default),
create_env() never replaces an existing environment. It keeps the
environment when it already has the requested packages. Otherwise, it
aborts (see Existing environments).
Arguments
- ...
Package match specs (MatchSpec strings), unnamed: character strings or character vectors, in order. Examples:
"python=3.13","bioconda::fastqc==0.12.1". With no specs,create_env()creates an empty environment.Or one environment file, given by
env_definition(), such asenv_definition("environment.yml"), without package specs. Package specs and a definition together, or two definitions, abort with classcondathis_create_env_conflicting_args. A file that does not exist aborts with classcondathis_create_env_missing_env_file. Withmethod = "auto", a new environment uses the first available backend incondathis.backend_priorityorder that does not say it cannot read the file. A file that the backend cannot read (any of them, with"auto") aborts with classcondathis_create_env_unsupported_definition(alsocondathis_backend_unsupported). Seeenv_definition()for the formats, and for the rules of lock files. No backend applies thevariables:of a YAML file: the commands that run in the environment do not get them.Any other value aborts with class
condathis_create_env_invalid_packages. Such values are:A named argument that
create_env()does not have. Names are never abbreviated:env =andpack =abort too. The error names the closest argument.A value that is not a character vector.
NAor"".A file name that ends in
.yml,.yaml,.jsonor.lock. Pass it withenv_definition().
packages = <specs>still works, andpackages = NULLcreates an empty environment. It is deprecated. It warns once per session (classcondathis_deprecated_packages_arg) when the call comes from the console, a script or the tests of the package that makes it. Calls made inside other packages do not warn, except in tests that use testthat's third edition (see condathis-conditions).create_env()aborts with classcondathis_create_env_positional_env_namewhenenv_nameis not given, the specs are two or more unnamed arguments, and the last of them is one string that names an existing environment. Name the argument, as inenv_name = "my-env". Specs given withpackages =or as one vector are never checked this way.- env_name
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Not empty, and not
.or...Not starting with
-, and not ending with..Without path separators,
:,#, whitespace, control characters or<>"|?*.Not a Windows device name, such as
NULorCOM1(see Environment names increate_env()).
Invalid values abort with class
condathis_invalid_env_name.run(),run_bin(),run_pipeline()andrun_step()also accept anenv_path()value. The other functions reject it with classcondathis_env_path_read_only.- method
Character string naming the backend.
"auto"(the default) uses the backend that ownsenv_namewhen it exists, and otherwise the first available backend ingetOption("condathis.backend_priority")order (see condathis-options). Any name fromlist_registered_backend_names()selects that backend, and"micromamba"is built in. The name of a backend whose packagecondathisknows, such as"rattler"of therattlerthispackage, also selects it.condathisloads the package on first use."native"is a deprecated alias for"micromamba"(warns once per session). The 0.1.4 defaultc("native", "auto")is read as"native".If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
condathis_backend_not_installed: the package of the named backend is not installed.condathis_backend_mismatch: the named backend does not own the environment, and the function changes it.condathis_backend_mismatch_warning(a warning): the same, for a function that does not change the environment.condathis_backend_ambiguous_env: several backends have an environment of that name, andmethodnames none of them.condathis_invalid_method: an invalid value.
- verbose
Character string that controls the console output. One of:
"output": show the output of the command and the messages ofcondathis."silent": show nothing."cmd": show the command line."spinner": show only a spinner."full": show the command line, the output, and the backend's own log.
TRUEmeans"output"andFALSEmeans"silent". Every level except"silent"shows a spinner in interactive sessions. It also shows these messages and this warning when they occur (see condathis-conditions):condathis_micromamba_downloading(a message): no usablemicromambawas found, so it is downloaded. Queries, such aslist_envs(), never download it.condathis_env_lock_waitingandcondathis_cache_lock_waiting(messages): the call waits for another R session.condathis_install_micromamba_checksum_unavailable(a warning): the checksum of the downloadedmicromambacould not be checked.
Invalid values abort with class
condathis_invalid_verbose. The default is shown in Usage.The command line shown, the
cmdof a result and the messages ofcondathisshow the password and the token of a URL as*****.micromambadoes the same (https://user:*****@host/channel,https://host/t/*****/channel). The command still gets them.- channels
A non-empty character vector of channel names or URLs, in priority order. For a package from another channel, either name the channel in the spec (
"bioconda::samtools") or add it here, as inchannels = c("conda-forge", "bioconda"). Invalid values, such asNULL,NAor"", abort with classcondathis_create_env_invalid_channels. condathis 0.1.4 also used"bioconda"by default. Whenchannelsis not given and the backend finds no package for a spec, the error says that the default changed.- additional_channels
NULL(the default) or a non-empty character vector of channel names or URLs, used afterchannels. Invalid values abort with these classes:condathis_create_env_invalid_channelscondathis_invalid_additional_channels
- channel_priority
Channel priority mode:
"strict"(the default),"flexible"or"disabled". With"strict", when several channels have a package, the solver uses only the builds from the first of them. This keeps the solution reproducible. The mamba documentation recommends this setting. Invalid values abort with classcondathis_create_env_invalid_channel_priority.- platform
NULL(the default) or the platform for the solver: a known conda platform (subdir) name in lower case, such as"linux-64","linux-aarch64","osx-64","osx-arm64","win-64","win-arm64"or"emscripten-wasm32". Other values abort with classcondathis_create_env_invalid_platformbefore anything runs. The message suggests a close name, such as"linux-aarch64"for"linux-arm64". When the channels have no packages for a known platform, the backend fails. Thencreate_env()aborts with classcondathis_create_env_failed. WithNULL, condathis can fall back to an emulated platform. This happens when the package specs or the environment file cannot be installed for the native platform, dependencies included, but can for the emulated one. This works with every backend that can tell whether a request solves for a platform, micromamba included. A lock file is never solved (seeenv_definition()). On Apple Silicon, condathis uses"osx-64"when Rosetta 2 is available. With a backend that solves for"win-arm64", condathis uses"win-64"through x64 emulation. Thewin-arm64micromamba, which a native ARM64 R on Windows installs, is such a backend.install_packages()later installs packages for the platform that the environment was created for, given or emulated. For an existing environment, see Existing environments.- env_file
NULL(the default) or the path of an environment file. Deprecated: passenv_definition(<path>)in...instead.env_file = pathstill works the same way. It warns once per session (classcondathis_deprecated_env_file_arg) when the call comes from the console, a script or the tests of the package that makes it. Calls made inside other packages do not warn.env_fileand anenv_definition()together abort with classcondathis_create_env_conflicting_args. A file that does not exist aborts with classcondathis_create_env_missing_env_file. With a lock file,channels,additional_channelsandchannel_priorityare ignored, as in 0.1.4.- overwrite
TRUEorFALSE(the default). WithFALSE,create_env()never replaces an existing environment.create_env()keeps the environment and runs nothing when it has every requested package (see Existing environments) or when no package is requested. For a lock file whose packages the backend reports, such as an@EXPLICIT, conda-lock or mambajs file with micromamba, it keeps the environment when it has exactly those packages (see Existing environments). It returns status 0. Otherwise, and always for an environment file that is solved, such asenvironment.yml,create_env()aborts with classcondathis_create_env_exists. Useinstall_packages()to add packages to an existing environment. Usevalidate_env()to check one. WithTRUE,create_env()creates the environment again from scratch, also when it exists or was built for anotherplatform. Whencreate_env()fails to create the new environment (a misspelled package, a download error), it keeps the existing one as it was. When it cannot move the existing one aside first (on Windows, while a program uses one of its files), it aborts with classcondathis_create_env_failedand changes nothing. Invalid values abort with classcondathis_create_env_invalid_overwrite.
Value
A condathis_result object, invisibly: a classed list with
status, stdout, stderr, timeout, pid, cmd and env_name.
cmd is the command line that the backend ran, or NA when the
backend reports none. cmd, stdout and stderr are NA when
nothing ran (an existing environment that already has the requested
packages). stdout, stderr and pid are NA when the backend
reports none, and pid always is with micromamba.
A backend failure aborts with class condathis_create_env_failed (also
condathis_backend_error), with the backend's error as the parent.
micromamba runs the link scripts of packages (pre-link and
post-link). A backend that does not, such as "rattler" of the
rattlerthis package, makes create_env() warn. The warning names
the packages, which may not work. Its classes are
condathis_link_scripts_skipped andcondathis_create_env_link_scripts_skipped.
Details
With the micromamba backend, create_env() adds the new environment to
~/.conda/environments.txt, the registry that conda and mamba share.
It does so only when micromamba needs your home directory, for example
for channel credentials you saved there (see Details in
get_install_dir()).
Existing environments
With overwrite = FALSE, create_env() compares an existing environment
with the request. validate_env() makes the same comparison.
An installed package satisfies a spec when it matches the name, version,
build string and channel of the spec. The name match ignores case:
"PyYAML" matches pyyaml. A spec without a channel must match a
package from channels or additional_channels. The channel comparison
ignores credentials and platform subdirectories, and compares a local
channel by its absolute path. "defaults" matches the pkgs/main and
pkgs/r packages it installs. The comparison uses only these bracket
constraints: version, build, build_number and channel. >=1.2.*
is read as >=1.2, as micromamba does. A build string matches with *
as its only wildcard.
A package from another channel does not satisfy a spec without a
channel. An environment built with condathis 0.1.4, which also used
"bioconda" by default, can have such packages. The error then names
the channel of the package. Add that channel to channels, or name it
in the spec, as in "bioconda::samtools".
Specs for virtual packages, whose names start with __, such as
"__cuda=12", "__unix" or "__glibc>=2.17", are not compared. They
describe the host, not the environment, and are never installed. The
solver checked them when it created the environment. create_env() and
install_packages() still pass them to the backend.
A spec that condathis cannot compare, or that micromamba, rattler and
conda read differently, never counts as satisfied. create_env() then
aborts for it with class condathis_create_env_exists. These are specs
with:
Another bracket constraint, such as
"zlib[md5=...]", or a group in parentheses at the end, such as"zlib (>=1.2,<2)"(read as bracket constraints).A version with
*after>,<,<=or~=("zlib<2.*").A version with
*in its middle ("zlib=1.*.3","zlib=1.3.*.*"), in!=1.2*or in=1.2*.A version with
*after>=, other than a single.*at the end ("zlib>=1.2*").~=with a one-part version ("zlib~=1"), an operator with no version ("zlib>=*"), a missing operand ("zlib>=1.2,"), abuild_numberwith==("zlib[build_number='==0']"), or a version that micromamba rejects ("zlib>==1.2").A build string with a character other than a letter, a digit,
_,.and*, such as a regular expression ("zlib=1.3.1=^h4.*$") or?.
A spec that condathis cannot read aborts with one of these classes, and
also with class condathis_invalid_arg:
condathis_parse_match_spec_invalid_name: a spec such as"::".condathis_parse_match_spec_invalid_url: the URL of a package file whose name is not<name>-<version>-<build>.
For a new environment, only the backend reads the specs. A spec it
cannot read aborts with class condathis_create_env_failed.
When platform is given, the platform of the installed packages must be
platform (noarch packages match any platform). A different platform
aborts with class condathis_create_env_platform_mismatch, and
create_env() keeps the environment. With platform = NULL, the
platform is not compared.
A lock file is compared by its packages, not by specs. The environment
must have exactly the packages that the lock lists for its platform (see
env_definition()): the same names, versions and build strings, none
missing and none more. Packages that pip installed are left out. A
difference aborts with class condathis_create_env_exists, and the
message names a few of the packages that differ. An environment file
that is solved, such as environment.yml, or a lock whose packages the
backend does not report, is never compared: an existing environment
aborts with class condathis_create_env_exists.
Other R sessions
Only one R session at a time changes an environment. create_env(),
install_packages() and remove_env() hold a lock on the environment
name while they work, with every backend. A call for an environment that
another R session is changing waits until that session is done. After
two seconds, the call says so with a message of class
condathis_env_lock_waiting. verbose = "silent" hides this message.
Ctrl-C stops the wait. clean_cache() waits until no other R session
creates an environment or installs packages. Those calls wait while it
cleans. Each wait gives a message of class condathis_cache_lock_waiting.
A lock lasts only as long as its session, also when the session crashes
or is killed. The lock files are in the directory locks of the
condathis data directory (see get_install_dir()). Where files cannot be
locked, such as on some network file systems, the call goes on without
the lock. When it changes something, it warns once per session with class
condathis_env_lock_unavailable.
Environment names
An env_name cannot be a Windows device name, on any OS. These names are
CON, PRN, AUX, NUL, CONIN$, CONOUT$, COM1 to COM9 and
LPT1 to LPT9, and COM or LPT followed by a superscript one, two
or three. The match ignores letter case and also applies with an
extension, such as nul.txt.
See also
condathis-conditions for every condition class, and condathis-options for the options that choose the backend.
Other environments:
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
remove_env(),
validate_env()
Examples
if (FALSE) { # \dontrun{
condathis::with_sandbox_dir({
# A local channel shipped with condathis, with `polyglot`: a
# dependency-free script that runs on Linux, macOS and Windows.
channel <- system.file(
"extdata", "polyglot-channel",
package = "condathis"
)
# Create a Conda environment from that channel, without network access
# once micromamba is installed.
condathis::create_env(
"polyglot",
env_name = "polyglot-env",
channels = channel
)
# A second call keeps the environment: it already has `polyglot`.
condathis::create_env(
"polyglot",
env_name = "polyglot-env",
channels = channel
)
# Create an empty environment.
condathis::create_env(env_name = "empty-env")
# Create a Conda environment and install the CLI `fastqc` in it.
# Explicitly using the channel `bioconda` and version `0.12.1`.
condathis::create_env(
"bioconda::fastqc==0.12.1",
env_name = "fastqc-env",
verbose = "output"
)
})
} # }