| Title: | Run Any CLI Tool in a 'Conda' Environment |
|---|---|
| Description: | Runs command line interface (CLI) tools in isolated and reproducible 'Conda' environments from R. Environments are created and managed with 'micromamba', which is downloaded when no usable copy is found. Commands run with their environment activated, alone or as pipelines connected by pipes. Other packages can provide other tools to create and run environments. |
| Authors: | Lucio Queiroz [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-6090-1834>), Claudio Zanettini [aut] (ORCID: <https://orcid.org/0000-0001-5043-8033>) |
| Maintainer: | Lucio Queiroz <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-11-21 23:24:56 UTC |
| Source: | https://github.com/luciorq/condathis |
Returns the root (data directory) that condathis assigns to a backend.
The root of the built-in "micromamba" backend is the condathis data
directory (see get_install_dir()). The root of every other backend is
the directory of its name inside it, for example
<condathis data directory>/rattler. A backend keeps its environments in
<root>/envs, and its caches in other directories of its root (see
Roots in register_backend()). The default functions of the backend
contract use this directory, and a backend package calls it to find its
root.
backend_root_dir(name)backend_root_dir(name)
name |
Character string, a backend name, registered or not. It
follows the rules of |
backend_root_dir() computes the path on every call, so it follows
with_sandbox_dir().
Part of the experimental backend extension API. See the
Lifecycle section of register_backend().
An fs_path, the absolute path of the root. When the root
exists, its real path (symbolic links resolved). Otherwise, the real
path of its nearest existing parent directory, followed by the rest of
the path. It creates nothing. Aborts with class
condathis_backend_invalid_name for a malformed name, and
condathis_backend_reserved_name (also condathis_backend_invalid_name)
for a reserved name other than "micromamba".
Other backends:
list_registered_backend_names(),
register_backend(),
unregister_backend()
condathis::with_sandbox_dir({ condathis::backend_root_dir("rattler") #> <data dir>/R/condathis/rattler })condathis::with_sandbox_dir({ condathis::backend_root_dir("rattler") #> <data dir>/R/condathis/rattler })
Removes the package and metadata caches of condathis and of every registered backend, and nothing else:
For the built-in micromamba backend, the package cache, pkgs, and
the repodata cache, cache, in its data directory (see
get_install_dir()), and home/.local there, where an earlier
create_env() could have installed the packages of a pip: section
(see PIP_USER in condathis-options).
For every other backend, its own package and metadata caches, and
conda-pkgs in its data directory. conda-pkgs is the package cache
of the Conda tools that run in its environments (see Child processes
in register_backend()).
The contents of the condathis cache directory,
tools::R_user_dir("condathis", "cache").
clean_cache() never deletes the per-user caches of conda, mamba and
micromamba, such as ~/.cache/conda, which other tools share.
clean_cache(verbose = c("output", "silent", "cmd", "spinner", "full"))clean_cache(verbose = c("output", "silent", "cmd", "spinner", "full"))
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
Environments keep the files of their packages. These files usually share
disk space with the package cache through hard links. You free that space
only by also removing those environments (see list_envs() and
remove_env()).
When the micromamba package cache does not exist, micromamba has nothing
to clean. clean_cache() then starts no process and does not install
micromamba. It still deletes the repodata cache and clears the condathis
cache directory.
clean_cache() loads a backend whose package condathis knows, such as
"rattler" of the rattlerthis package, when its data directory has
caches or environments. When that package is not installed,
clean_cache() does not clean its caches and warns with class
condathis_backend_not_installed.
clean_cache() waits until no other R session creates an environment
or installs packages. Those sessions wait until it is done (see Other R
sessions in create_env()).
When a backend fails to clean its caches, clean_cache() still cleans
the caches of the other backends and the directories above. Then it
aborts with the first failure. That error has the classes
condathis_clean_cache_failed and condathis_backend_error, and the
error of the backend as its parent. When clean_cache() cannot delete a
directory itself, it aborts with class condathis_clean_cache_failed the
same way.
A condathis_result object, invisibly: a classed list with
status, stdout, stderr, timeout, pid, cmd and env_name.
The values come from the micromamba command that ran, and cmd is its
command line.
When no micromamba command ran, status is 0, timeout is FALSE
and the other fields are NA. pid is always NA, and so is
env_name: the caches are not tied to an environment.
clean_cache() keeps micromamba and the environments. To remove
everything that condathis installed, delete its data and cache
directories, in an R session that runs no condathis command at the
same time:
unlink(condathis::get_install_dir()$path, recursive = TRUE)
unlink(tools::R_user_dir("condathis", "cache"), recursive = TRUE)
The condathis data directory, the path of the "micromamba" row of
get_install_dir(), holds the micromamba binary that
install_micromamba() downloaded, every environment, the package and
repodata caches, the lock files and the configuration file that
condathis writes for micromamba. The data
directories of the other backends that use backend_root_dir() are
inside it. get_install_dir() also lists the data directory of a
registered backend that chose its own.
This leaves alone what condathis did not install: a micromamba that
condathis found elsewhere (see micromamba discovery in
condathis-options), environments that you passed as env_path(),
the lines that micromamba added to ~/.conda/environments.txt, the pip
cache on macOS and Windows (see get_install_dir()), and on Windows the
Start Menu shortcuts that condathis 0.1.4 and earlier added (see
remove_env()).
condathis-conditions for every condition class.
Other setup:
get_install_dir(),
get_sys_arch(),
install_micromamba(),
micromamba_bin_path(),
with_sandbox_dir()
condathis::with_sandbox_dir({ condathis::clean_cache(verbose = "output") })condathis::with_sandbox_dir({ condathis::clean_cache(verbose = "output") })
Every error that condathis raises has the class condathis_error, and
every warning has the class condathis_warning. Each condition also has
more specific classes. Use them to handle one kind of problem with
base::tryCatch(), base::withCallingHandlers() or
rlang::try_fetch(), and to test for it with
testthat::expect_error(class = ). Do not match the text of a message:
it can change in any release.
The classes of a condition go from the most specific to the most general:
The class of the function and the problem,
condathis_<function>_<problem>, with the full name of the exported
function. For example:
condathis_create_env_exists
condathis_run_bin_env_not_found
Older names of that class, kept so that existing handlers still work (see Renamed classes). Some classes carry further names that this page does not list: do not rely on them.
Shared classes for the kind of problem. For example:
condathis_invalid_overwrite and condathis_invalid_arg
condathis_env_not_found
The root class, condathis_error or condathis_warning.
The rlang package adds its own classes after these, such as
rlang_error, error and condition.
For example, create_env(overwrite = "yes") aborts with these classes:
c( "condathis_create_env_invalid_overwrite", "condathis_create_invalid_overwrite_arg", "condathis_invalid_overwrite", "condathis_invalid_arg", "condathis_error" )
The checks of verbose, method and error are the same in every
function, so their errors have only shared classes, for example:
c( "condathis_invalid_verbose", "condathis_invalid_arg", "condathis_error" )
Handle the most general class that fits. A handler for
condathis_env_not_found catches a missing environment in every
function, and a handler for condathis_error catches every error of
condathis.
condathis_invalid_arg
An argument has an invalid value. condathis checks the arguments
before it changes anything, so such an error has no side effects.
condathis_invalid_<argument>
An invalid value of one argument, with its exact name. It always comes
with the class condathis_invalid_arg. For example:
condathis_invalid_env_name
condathis_invalid_packages
condathis_invalid_channels
condathis_invalid_method
condathis_invalid_verbose
condathis_invalid_error
condathis_invalid_timeout
condathis_parse_match_spec_invalid_namecondathis_parse_match_spec_invalid_url
A package spec that condathis cannot read, such as "::", or the URL
of a package file whose name is not <name>-<version>-<build>.
condathis reads the specs when it compares them with an existing
environment, in create_env(), install_packages() and
validate_env(). Also condathis_invalid_arg.
condathis_env_not_found
The environment does not exist. A missing environment is created
only by run(), run_bin(), run_pipeline() and
install_packages(), and only the default "condathis-env". With
error = "continue", the run family returns status 127 instead. When
the environment is in the data directory of a backend whose package
cannot be used, the message names that backend (see the class
condathis_backend_not_installed below).
condathis_backend_error
A backend failed. The function classes are:
condathis_<function>_failed
condathis_<function>_resolve_failed
a command or its activation could not be resolved.
condathis_backend_probe_failed
The backend's error is the parent, so its classes are found by
rlang::cnd_inherits(). The condathis_* classes of the backend's
error are also copied, for example:
condathis_micromamba_status_error
condathis_backend_probe_failed
A backend could not tell whether the environment exists.
create_env(), install_packages() and remove_env() then stop
before they change anything. Also condathis_backend_error.
condathis_backend_query_failed (a warning)
With method = "auto", a query of one backend failed, and the
function skipped that backend.
condathis_backend_invalid_return
A backend returned a value that breaks the contract of
register_backend(). The message names the backend. Also:
condathis_backend_contract_violation
For the value of backend_resolve_run(), the first class is:
condathis_backend_resolve_run_invalid
condathis_backend_contract_violation
A backend breaks the contract, when it is registered or in a return
value.
condathis_backend_not_installed
The package of a backend that condathis knows, such as "rattler" of
the rattlerthis package, is not installed. It is:
an error when method names that backend (with the classes of an
invalid method).
an error when a call would change an environment in the data
directory of that backend (with condathis_backend_mismatch).
a warning when a query skips the environments of that backend (once per session).
a warning when clean_cache() cannot clean its caches.
condathis_backend_load_failed
The same, when the package is installed but failed to load, did not
register its backend, or its backend was unregistered in this
session. The error of the load is the parent. Also a warning, once per
session, when condathis tried to load the package. It tries this
when its backend has environments or caches, or when the option
condathis.backend_priority names it.
condathis_link_scripts_skipped (a warning)
The backend did not run the pre-link, post-link or pre-unlink scripts
of some packages, which micromamba runs, so these packages may not
work. The call itself succeeded. The warning has the fields backend,
env_name, packages (the package names, sorted) and scripts (a
data frame with the columns package and script).
condathis_backend_quiesce_failed (a warning)with_sandbox_dir() or clean_cache() could not tell whether a
backend still works in the R process, and went on.
condathis_env_lock_waiting (a message, neither an error nor a
warning)create_env(), install_packages() or remove_env() waits for
another R session that changes the same environment (see Other R
sessions in create_env()).
condathis_cache_lock_waiting (a message)clean_cache() waits for other R sessions that create environments or
install packages, or these wait for a clean_cache() of another
session.
condathis_micromamba_downloading (a message)
A function that needs micromamba found no usable binary and
downloads the default version with install_micromamba(). The message
names the version and the path. verbose = "silent" hides it.
condathis_env_lock_unavailable (a warning, once per session)
The lock of the environment or of the package caches could not be
taken, for example on a file system that cannot lock files. The call
went on without it.
condathis_status_error
A command of run(), run_bin() or run_pipeline() exited with a
status other than 0.
condathis_timeout_error
A command of run(), run_bin() or run_pipeline() ran longer than
timeout and was killed.
condathis_micromamba_status_error
A micromamba command that condathis started for the micromamba
backend failed. It carries the fields status and stderr, also when
it is the class of a backend failure that condathis re-raised.
Deprecated arguments and values, which still work but will be removed (warnings):
condathis_deprecated_packages_arg
for packages = in create_env(), install_packages() and
validate_env(): once per session and function, for calls from the
console, a script or the tests of the calling package. Calls made
inside other packages do not warn.
options(lifecycle_verbosity = "warning") makes those calls warn
too, and "quiet" turns the warning off. testthat's third edition
sets lifecycle_verbosity = "warning" inside test_that(), so in
those tests calls made inside other packages, such as a dependency
that calls condathis, warn too;
withr::local_options(lifecycle_verbosity = "quiet") silences them.
condathis_deprecated_env_file_arg
for env_file = in create_env(): pass an env_definition() in
... instead. The same rule as for packages =.
condathis_deprecated_method_native
for method = "native" (once per session), in every function that
takes method. The same rule as for packages =.
condathis_deprecated_arg
for timeout_limit in install_micromamba().
The status and timeout errors of run(), run_bin() and
run_pipeline() carry these fields, so a handler does not need to read
the message:
status: the exit status, an integer. It is -9 for a timeout, and
127 for a command that could not start. On Linux and macOS, a
command killed by signal n has the status 128 + n, as in a shell
(137 for SIGKILL, 141 for SIGPIPE).
stdout, stderr: the captured output, or NA when that stream was
not captured.
timeout: TRUE for a timeout, FALSE otherwise.
The errors of run_pipeline() also carry result, the
condathis_pipeline result, and statuses, the status of each command.
Each function also raises the shared classes above. The checks of
verbose, method and error raise only shared classes.
The classes of create_env(). Arguments:
condathis_create_env_invalid_packages
condathis_create_env_positional_env_name
condathis_create_env_invalid_env_name
condathis_create_env_invalid_channels
condathis_create_env_invalid_channel_priority
condathis_create_env_invalid_platform
condathis_create_env_invalid_env_file
an invalid value of the deprecated env_file.
condathis_create_env_missing_env_file
the file of an env_definition() or of env_file does not exist.
condathis_create_env_invalid_overwrite
condathis_create_env_conflicting_args
package specs and an env_definition(), two definitions, a definition
and env_file, or channels, additional_channels or
channel_priority with a lock file given by env_definition(). The
deprecated env_file ignores them, as in 0.1.4.
condathis_create_env_unsupported_definition
the backend cannot read the env_definition(), or no available
backend can with method = "auto". Also
condathis_backend_unsupported.
The environment:
condathis_create_env_exists
it exists, and overwrite = FALSE cannot keep it. A lock file keeps
it only when the environment has exactly the packages of the lock.
condathis_create_env_platform_mismatch
condathis_create_env_platform_not_locked
a lock file lists none of the platforms that create_env() can use.
Also condathis_create_env_platform_mismatch.
The backend:
condathis_create_env_failed
also when a lock file that lists packages gives an empty environment.
condathis_create_env_link_scripts_skipped (a warning)
The classes of install_packages(). Arguments:
condathis_install_packages_missing_packages
condathis_install_packages_invalid_packages
condathis_install_packages_positional_env_name
condathis_install_packages_invalid_env_name
condathis_install_packages_invalid_channels
condathis_install_packages_invalid_channel_priority
condathis_install_packages_conflicting_args
package specs and an env_definition(), or two definitions.
condathis_install_packages_missing_env_file
the file of an env_definition() does not exist.
condathis_install_packages_unsupported_definition
a lock file, or a file that the backend cannot read or install from
(then also condathis_backend_unsupported).
The environment:
condathis_install_packages_env_not_found
The backend:
condathis_install_packages_failed
condathis_install_packages_link_scripts_skipped (a warning)
condathis_install_packages_missing_previous_channels (a warning)
a channel the environment was built from is not in the call. This
holds on every backend that records the channels in
conda-meta/history.
The classes of remove_env():
condathis_remove_env_invalid_env_name
condathis_remove_env_env_not_found
condathis_remove_env_failed
condathis_remove_env_link_scripts_skipped (a warning)
pre-unlink scripts.
The classes of clean_cache():
condathis_clean_cache_failed
a backend failed to clean its caches, or condathis could not empty
one of its own cache directories. condathis raises it after it
cleaned the other backends and directories.
A backend failure also has condathis_backend_error, with the error
of the backend as the parent. For a non-zero status that the
backend returned without an error, it has the fields status,
stdout and stderr instead.
A directory failure has the error of the deletion as the parent.
condathis_backend_invalid_return
a backend returned a status that is not a whole number.
condathis_backend_not_installed and
condathis_backend_load_failed (warnings)
name a backend whose caches were not cleaned.
The classes of validate_env(). Arguments:
condathis_validate_env_invalid_packages
condathis_validate_env_positional_env_name
condathis_validate_env_invalid_env_name
condathis_validate_env_invalid_channels
condathis_validate_env_invalid_platform
condathis_validate_env_conflicting_args
package specs and an env_definition(), or two definitions.
condathis_validate_env_missing_env_file
the file of an env_definition() does not exist.
condathis_validate_env_unsupported_definition
a file that cannot be compared: a request such as environment.yml,
a lock whose packages the backend does not report, or a lock without
packages for platform. Also condathis_backend_unsupported when the
backend cannot read the file.
The environment:
condathis_validate_env_env_not_found
condathis_validate_env_unsatisfied
a spec is not satisfied, or the environment does not have exactly the
packages of a lock file.
The backend:
condathis_validate_env_failed
These are the classes of the queries, with the name of the function as
<function>. The queries are env_exists(), list_envs(),
list_packages(), get_env_dir() and get_install_dir().
condathis_<function>_invalid_env_name
for the functions that take env_name.
condathis_list_packages_env_not_found
condathis_<function>_failed
not for get_env_dir().
The classes of install_micromamba(). Arguments:
condathis_install_micromamba_invalid_micromamba_version
condathis_install_micromamba_invalid_timeout
condathis_install_micromamba_invalid_download_method
condathis_install_micromamba_invalid_force
condathis_install_micromamba_conflicting_argstimeout and timeout_limit.
Then:
condathis_install_micromamba_unsupported_version
condathis_install_micromamba_download_failed
The warnings about the SHA256 check of a download:
condathis_install_micromamba_checksum_unavailable
the binary is installed without the check. verbose = "silent" hides
it.
condathis_install_micromamba_checksum_mismatch
the binary is not installed. Shown also with verbose = "silent".
condathis_micromamba_downloading (a message)
no usable binary was found, so it is downloaded.
condathis_micromamba_status_error
a micromamba command failed.
condathis_micromamba_env_file_dir_not_writable
the directory of an environment file with a pip: section is not
writable, so micromamba cannot write its temporary file there, and the
section names paths relative to that directory, so condathis cannot
pass a copy. create_env() and install_packages() raise it with
their class of a backend failure.
condathis_micromamba_bin_path_not_executable
condathis_micromamba_version_not_detected
condathis_micromamba_not_available_for_arch
For create_env() with overwrite = TRUE, on every backend, three
classes apply:
condathis_env_set_aside_failed
the existing environment could not be moved aside, so it is
unchanged.
condathis_env_not_restored
the create failed and the old environment could not be moved back.
The error has the field kept_env_dir with where it is kept.
condathis_env_restore_failed (a warning)
the same after an interrupt, also with kept_env_dir.
The micromamba backend adds:
condathis_micromamba_env_set_aside_failed
condathis_micromamba_env_restore_failed
When condathis replaces, removes or cleans up an environment, it
refuses to delete or move a directory that is not exactly
<root>/envs/<env_name>. The error has one of these classes:
condathis_unsafe_env_dir_delete
condathis_unsafe_env_dir_move
The classes of run() and run_bin(), with run or run_bin as
<function>. Arguments:
condathis_<function>_invalid_cmd
condathis_<function>_invalid_args
a value in ..., also condathis_invalid_cmd_args.
condathis_<function>_invalid_input
condathis_<function>_invalid_binary
condathis_<function>_invalid_env_name
condathis_<function>_invalid_<argument>
for timeout, supervise, cleanup_tree, linux_pdeathsig,
stdin, stdout, stderr and activate.
Then:
condathis_<function>_env_not_found
condathis_<function>_resolve_failed
condathis_<function>_status_error
condathis_<function>_timeout_error
A failed activation of the micromamba backend adds the classes of its error to the resolve error:
On Linux and macOS, an activate.d script that exits with a non-zero
status adds two classes:
condathis_micromamba_status_error
condathis_cmd_status_error
A missing or unreadable activation result adds
condathis_activation_dump_error.
A missing environment directory adds
condathis_activation_env_not_found.
The classes of run_pipeline(). Arguments:
condathis_run_pipeline_invalid_step
condathis_run_pipeline_too_few_commands
condathis_run_pipeline_conflicting_method
condathis_run_pipeline_invalid_env_name
condathis_run_pipeline_invalid_input
condathis_run_pipeline_invalid_binary
condathis_run_pipeline_invalid_<argument>
for timeout, supervise, cleanup_tree, linux_pdeathsig,
activate, stdin, stdout and stderr.
Then:
condathis_run_pipeline_env_not_found
condathis_run_pipeline_resolve_failed
condathis_run_pipeline_status_error
condathis_run_pipeline_timeout_error
The classes of run_step():
condathis_run_step_invalid_cmd
condathis_run_step_invalid_args
condathis_run_step_invalid_env_name
condathis_run_step_invalid_method
condathis_run_step_invalid_stderr
The classes of env_path():
condathis_env_path_invalid_path
the path argument.
condathis_env_path_invalid
a malformed env_path() object. It is also the second class of a
path error.
condathis_env_path_read_only
passed to a function that takes only names.
condathis_env_path_unsupported_method
a method that names a backend that cannot run commands in such an
environment, also condathis_backend_unsupported.
condathis_env_path_not_foundcondathis_env_path_not_conda_env
also condathis_env_not_found.
The classes of env_definition():
condathis_env_definition_invalid_path
the path argument, also a URL. Also condathis_invalid_path.
condathis_env_definition_invalid_format
condathis_env_definition_invalid_options
an unnamed or repeated option in ....
condathis_env_definition_invalid
a malformed env_definition() object, found by the function that gets
it.
A definition passed to a function that takes only package specs or names aborts with the class of the invalid argument of that function.
The classes of parse_output():
condathis_parse_output_invalid_res
condathis_parse_output_invalid_stream
condathis_parse_output_invalid_trim
condathis_parse_output_binary_stream
a raw stream cannot be parsed as text.
The classes of with_sandbox_dir():
condathis_with_sandbox_dir_cleanup_failed (a warning)
the sandbox could not be deleted.
method)The classes of the choice of a backend with method:
condathis_backend_not_registered
condathis_backend_none_available
condathis_backend_mismatch
a change to an environment of another backend.
condathis_backend_ambiguous_env
several backends have the environment.
condathis_backend_not_installedcondathis_backend_load_failed
the package of the backend cannot be used.
The warnings:
condathis_backend_mismatch_warning
condathis_backend_marker_mismatch
condathis_invalid_backend_priority_option
The classes of register_backend() and unregister_backend():
condathis_backend_invalid_name
condathis_backend_reserved_name
condathis_backend_root_conflict
the condathis data directory has an entry of that name that is not a
directory.
condathis_backend_name_conflict
the name differs only in case from another backend name.
condathis_backend_class_conflict
condathis_backend_contract_violation
A backend gives its own condition the class
condathis_backend_unsupported when it cannot honor an argument, and
never the class condathis_backend_error.
These classes of condathis 0.1.4 were renamed to follow the scheme.
Each old name is kept as an extra class until condathis 1.0, so
existing handlers keep working. Use the new names in new code. Each item
gives the new class, then the old one:
condathis_create_env_invalid_overwrite
old: condathis_create_invalid_overwrite_arg
condathis_create_env_missing_env_file
old: condathis_create_missing_env_file
condathis_remove_env_env_not_found
old: condathis_error_env_remove
condathis_list_packages_env_not_found
old: condathis_list_packages_missing_env
condathis_install_micromamba_download_failed
old: condathis_install_error_missing_bzip2
condathis_micromamba_bin_path_not_executable
old: condathis_umamba_bin_path_not_executable
condathis_micromamba_version_not_detected
old: condathis_umamba_version_not_detected
condathis_micromamba_not_available_for_arch
old: condathis_umamba_not_available_for_arch
condathis_micromamba_status_error
old: condathis_cmd_status_error
condathis_run_invalid_cmd
old: condathis_run_null_cmd
condathis_run_invalid_stdincondathis_run_bin_invalid_stdin
old: condathis_run_stdin_error
condathis_run_bin_status_error
old: condathis_run_status_error
condathis_run_invalid_argscondathis_run_bin_invalid_args
(a named value) old: rlib_error_dots_named, rlib_error_dots
condathis_install_error_missing_bzip2 is deprecated: a failed download
does not depend on bzip2.
condathis-options, register_backend()
condathis::with_sandbox_dir({ # A missing environment, in any function print(tryCatch( condathis::list_packages(env_name = "no-such-env"), condathis_env_not_found = function(cnd) "not found" )) # An invalid argument aborts before anything runs print(tryCatch( condathis::create_env(env_name = "my-env", overwrite = "yes"), condathis_invalid_arg = function(cnd) class(cnd) )) }) ## Not run: condathis::with_sandbox_dir({ # The fields of a status error. The command is the Rscript of this R, # run in the default environment, which is created empty. rscript <- file.path( R.home("bin"), if (.Platform$OS.type == "windows") "Rscript.exe" else "Rscript" ) tryCatch( condathis::run(rscript, "-e", "quit(status = 3)", verbose = "silent"), condathis_status_error = function(cnd) cnd$status ) }) ## End(Not run)condathis::with_sandbox_dir({ # A missing environment, in any function print(tryCatch( condathis::list_packages(env_name = "no-such-env"), condathis_env_not_found = function(cnd) "not found" )) # An invalid argument aborts before anything runs print(tryCatch( condathis::create_env(env_name = "my-env", overwrite = "yes"), condathis_invalid_arg = function(cnd) class(cnd) )) }) ## Not run: condathis::with_sandbox_dir({ # The fields of a status error. The command is the Rscript of this R, # run in the default environment, which is created empty. rscript <- file.path( R.home("bin"), if (.Platform$OS.type == "windows") "Rscript.exe" else "Rscript" ) tryCatch( condathis::run(rscript, "-e", "quit(status = 3)", verbose = "silent"), condathis_status_error = function(cnd) cnd$status ) }) ## End(Not run)
condathis reads a small set of R options and environment variables to
locate micromamba, choose a backend, and resolve its data directories.
It also builds an isolated environment for every child process it
spawns. That isolation clears or overrides many CONDA_* and MAMBA_*
variables, so values set in the calling session never reach micromamba
or the tools it runs.
This page leaves out fallbacks that apply only when the variables listed
here are unset, such as HOMEDRIVE and HOMEPATH on Windows.
Set these with base::options(), for example in an .Rprofile file.
condathis.micromamba_pathCharacter string. Path to a micromamba binary to use instead of
the one managed by condathis. It has the highest priority in the
micromamba discovery order (see micromamba discovery).
The binary must report a compatible version (2.8.1 or newer).
Otherwise, condathis uses the next candidate. Default: NULL
(unset).
condathis.backend_priorityCharacter vector. The order of the registered backends for
method = "auto". A new environment goes to the first available
backend in this order: in create_env(), and when run(),
run_bin(), run_pipeline() or install_packages() create
"condathis-env". list_envs() and get_install_dir()
report the backends in this order. The vector sets an order, not an
allowlist: registered backends missing from the vector come after the
listed ones, in alphabetical order. condathis loads a backend
package that it knows, such as "rattler" of rattlerthis, when the
vector lists the backend and a new environment needs a backend. The
vector therefore applies even when nothing else loaded the package.
Other names that are not registered are ignored. A value that is not
a character vector without NA warns once per session with class
condathis_invalid_backend_priority_option and is ignored.
Default: "micromamba", so loading another backend package does not
change where condathis creates new environments. An existing
environment always uses the backend that owns it.
timeoutNumeric. Base R download timeout in seconds. While
install_micromamba() downloads the binary, condathis uses the
larger of this value and the timeout argument as the limit
for each download. The limit applies to both curl and
utils::download.file(). Inf, or 0 when both values are 0,
means no limit. condathis lowers a finite limit above 2147483
seconds (about 24.8 days) to that value, because older libcurl
versions reject larger values. condathis ignores a session value
that is not a single, non-negative number. It restores the session
value afterwards.
For example, this call in an .Rprofile file uses a specific
micromamba binary, and creates new environments with the "rattler"
backend when the rattlerthis package is installed (micromamba stays
the fallback):
options(
condathis.micromamba_path = "/opt/micromamba/bin/micromamba",
condathis.backend_priority = c("rattler", "micromamba")
)
Set these in the shell, in an .Renviron file, or with
base::Sys.setenv().
CONDATHIS_MICROMAMBA_PATHPath to a micromamba binary. Same effect as the
condathis.micromamba_path option, with lower priority than that
option.
CONDA_PREFIXPrefix of the Conda environment active in the calling shell.
condathis reads it to look for micromamba inside that prefix
during discovery, and to remove the activation of the R session from
child processes (see The activation of the R session below). It
never passes it on to child processes.
PATHSearched for micromamba as the last discovery fallback. Also the
base PATH of child processes, without the binary directories of
the Conda and pixi environments that the R session runs in (see
below). run(), run_bin() and run_pipeline() put the
environment's binary directories in front of it.
PATHEXTWindows only. Extensions tried when a command name is resolved
inside an environment. Default when unset: .COM;.EXE;.BAT;.CMD.
TARA system tar program, as used by base R: a program name, looked
up on PATH, or the path of an executable file.
install_micromamba() extracts the micromamba archive with R's
internal tar, and uses this program only when that fails. It skips
the value internal, an empty value, and a program that cannot be
found or run, and uses tar on PATH instead. TAR does not
support arguments.
For example, this line of an .Renviron file names the same micromamba
binary as the option above:
CONDATHIS_MICROMAMBA_PATH=/opt/micromamba/bin/micromamba
condathis keeps micromamba, its environments and its package cache
in the condathis data directory, tools::R_user_dir("condathis", "data") (see get_install_dir()). Every other backend keeps its
environments and caches in a directory of its name inside it, such as
R/condathis/rattler (see backend_root_dir()). These variables move
those directories through the rules of tools::R_user_dir(). Backends
have no options or environment variables of their own for them.
R_USER_DATA_DIRBase data directory. Takes precedence over XDG_DATA_HOME. The
condathis data directory is its R/condathis subdirectory.
XDG_DATA_HOMEBase data directory when R_USER_DATA_DIR is unset. On macOS, when
both are unset, condathis uses ~/.local/share instead of the
platform default. That default is under
~/Library/Application Support, which contains a space, and
micromamba run can fail on paths with spaces.
R_USER_CACHE_DIR, XDG_CACHE_HOME
Base cache directory, in that order. clean_cache() empties its
R/condathis subdirectory.
HOME, USERPROFILE, APPDATA, LOCALAPPDATA
Home and application data directories. tools::R_user_dir() uses
them when none of the variables above is set: on Windows, APPDATA
for the data directory and LOCALAPPDATA for the cache directory.
condathis creates the condathis data directory only when a call needs
it. Queries, such as list_envs(), env_exists(), list_packages() and
validate_env(), create no environment and never install micromamba.
get_install_dir() and get_env_dir() create only the data directory.
with_sandbox_dir() sets all the data and cache variables above to
temporary directories. Environments, packages and the micromamba
binary that condathis installs inside it, with every backend, then stay
out of your own directories.
install_micromamba() downloads with curl::curl_download() when
curl 5.0.0 or later is installed, and with utils::download.file()
otherwise. Both honor the standard proxy variables, such as
http_proxy, https_proxy, and no_proxy.
The processes that condathis starts, micromamba included, inherit
these variables from the R session, so micromamba downloads packages
through the same proxy. It ignores the proxy settings of your
.condarc and .mambarc files (see CONDARC below).
These variables also reach every process unchanged, on purpose:
SSL_CERT_FILE, REQUESTS_CA_BUNDLE, PIP_CERT and the other
certificate variables of the tools that a process runs.
Such as PIP_INDEX_URL, PIP_EXTRA_INDEX_URL, PIP_CONFIG_FILE
(except for micromamba list, see below), UV_INDEX_URL and
NETRC. micromamba create installs the pip: section of an
environment file with them.
CONDA_OVERRIDE_*Such as CONDA_OVERRIDE_CUDA, CONDA_OVERRIDE_GLIBC and
CONDA_OVERRIDE_OSX. They set the virtual packages (__cuda,
__glibc, __osx) that micromamba solves for, also with
--no-env. For example, CONDA_OVERRIDE_CUDA = "12.4" gets the
CUDA builds of packages on a machine without a GPU.
Every process condathis starts, whether micromamba itself or a
command run by run(), run_bin() or run_pipeline(), starts from a
copy of the calling session's environment, without the activation of
the R session (see The activation of the R session below).
condathis then applies the overrides below to that copy only.
condathis never modifies the calling R session. A process that you start yourself does not get these
overrides. Pass --no-rc and --no-env to micromamba or conda to
ignore your own Conda settings.
Cleared or reset, so that the user's own Conda or Mamba setup does not interfere:
CONDARC, MAMBARC
Set to "". With the micromamba backend, condathis also calls
micromamba with --no-env and with --rc-file pointing at
condathis-micromamba.yaml in the condathis data directory. So
micromamba ignores the user's configuration files and MAMBA_*
settings. That file pins pkgs_dirs to the condathis package
cache, and sets shortcuts: false, so that micromamba adds no Start
Menu shortcuts on Windows. One exception: micromamba extracts
packages in subprocesses (micromamba package extract) that it
starts without these options. These subprocesses still read the
user's configuration files, such as ~/.condarc, ~/.mambarc and
those in XDG_CONFIG_HOME. They also read the MAMBA_* variables
that are not listed here.
CONDA_ROOT_PREFIX, MAMBA_ROOT_PREFIX
Set to "" for every command of an environment, also when the
activation of the micromamba backend sets MAMBA_ROOT_PREFIX, as it
does on Windows. micromamba itself gets the condathis data
directory as its root prefix, with -r and in MAMBA_ROOT_PREFIX.
Without MAMBA_ROOT_PREFIX, micromamba (2.8.1 to 2.10.0 checked)
refuses to start, even for --version, when its default root prefix
exists but is not a Conda environment. The default root prefix is $XDG_DATA_HOME/mamba, else
~/.local/share/mamba, on Windows else mamba in the roaming
application data folder.
CONDA_PREFIX, MAMBA_PREFIX
Set to "".
CONDA_DEFAULT_ENV, MAMBA_DEFAULT_ENV
Set to "".
CONDA_PROMPT_MODIFIER, MAMBA_PROMPT_MODIFIER
Set to "".
CONDA_SHLVL, MAMBA_SHLVL
Set to "0". The commands of run(), run_bin() and
run_pipeline() get "1" (see below).
CONDA_PKGS_DIRS, MAMBA_PKGS_DIRS
For micromamba and the commands of its environments, environments
given by env_path() included: the pkgs/ directory of the
condathis data directory. Packages are cached only there. The user's
own ~/.mamba/pkgs cache is never read or written, and
clean_cache() never cleans it. For the commands of other backends'
environments: the directory conda-pkgs/ next to the envs/
directory that holds the environment, in the backend's data
directory. A Conda tool run in such an environment caches its
packages there, and clean_cache() empties it. It is "" when the
environment is not in a directory named envs. An environment given
by env_path() that such a backend runs gets the backend's own
conda-pkgs/, not one next to the environment. With
activate = TRUE, the activation of such a backend can set another
value (see register_backend()).
MAMBA_ENVS_PATH, MAMBA_ENVS_DIRS
Set to "".
CONDA_ENVS_DIRSRemoved from the child environment.
CONDA_ENVS_PATHFor micromamba and the commands of its environments, environments
given by env_path() included: the envs/ directory of the
condathis data directory. For the commands of other backends'
environments: the parent directory of the environment, and for an
environment given by env_path(), the backend's own envs/
directory. The value is the same with activate = TRUE and
activate = FALSE. With activation, the backend can set another
value.
R_HOMERemoved, with every other R_* variable (see The startup of R
below), so an R installed in a Conda environment does not pick up
the R installation of the calling session.
TMPDIRSet to a new temporary directory for each call. condathis removes
it when the call returns.
TMPOn Windows, for every micromamba command: a directory in its
TMPDIR. micromamba writes its temporary files there, such as the
batch files of micromamba run, so they are removed with that
directory, also when the command is stopped. The activate.d
scripts see this value while the activation is recorded. A value
that they build from it names the session's TMP, unless they
wrote something in that directory: then the value names that
directory, which the command finds in its TMPDIR, and the
activation is recorded again for every command. The commands of
run(), run_bin() and run_pipeline() keep the session's value,
unless an activate.d script sets one. TEMP is never changed.
XDG_CACHE_HOMEFor every micromamba command: the cache/ directory of the
condathis data directory. There micromamba keeps its repodata cache,
instead of in ~/.cache/conda, and the mamba/proc directory of
micromamba run. The scripts that packages run when they are
installed or removed see this value too. The activate.d scripts,
while the activation is recorded, and the commands of run(),
run_bin() and run_pipeline() keep the session's value.
HOME (USERPROFILE on Windows)For micromamba env list, micromamba env remove and, unless it
needs your home directory, micromamba create: the home/
directory of the condathis data directory. So micromamba does not
rewrite ~/.conda/environments.txt (see Details in
get_install_dir()). The scripts that packages run when they are
installed or removed by these commands see this value too. On
Windows, micromamba looks there for the Start Menu shortcuts of the
removed packages.
Python, pip and uv: the Python state of the R session never reaches a
process of condathis. So the python of an environment finds only its
own modules, and micromamba create installs the pip: section of an
environment file into the environment, never elsewhere. For every
process, micromamba itself and the commands of run(), run_bin()
and run_pipeline(), with and without activation:
PYTHONHOME, PYTHONPATH, PYTHONUSERBASE, PYTHONSTARTUP
Removed. To give a command a PYTHONPATH, set it in the command,
such as run("env", "PYTHONPATH=/my/modules", "python", "script.py")
on Linux and macOS, or add the directory to sys.path in the
script.
PYTHONNOUSERSITESet to "1": the user's site directory (~/.local/lib/python3.*,
on Windows a Python directory in APPDATA) is not on sys.path.
UV_PYTHON, UV_SYSTEM_PYTHON, UV_PROJECT_ENVIRONMENT
Removed, so uv uses the python of the environment.
PIP_USER, PIP_REQUIRE_VIRTUALENV
Set to "false", which overrides user and require-virtualenv in
a pip configuration file; PIP_REQUIRE_VENV, an alias that pip
also reads, is removed. Otherwise pip installed into the user's
site directory, or failed: the user's site directory is off, and a
Conda environment is not a virtual environment. So
run("python", "-m", "pip", "install", ...) installs into the
environment.
PIP_TARGET, PIP_PREFIX, PIP_ROOT
Removed, whatever their value. A target, prefix or root in a
pip configuration file still applies (an environment variable
cannot unset it). To install elsewhere, pass --target or
--prefix to pip in the command.
An activated virtual environment of the session (VIRTUAL_ENV) is
undone as well (see The activation of the R session below). The
activation of the environment of a command comes after all this, so a
variable that an activate.d script sets reaches the command.
For micromamba create and micromamba install, which run pip, or uv
when the environment file lists it, for the pip: section,
VIRTUAL_ENV and VIRTUAL_ENV_PROMPT are also removed, whatever their
value.
For micromamba list, which list_packages() runs, and which runs
python -m pip inspect in the environment: PIP_CONFIG_FILE is the
null device (/dev/null, on Windows nul), so pip reads no
configuration file, PIP_USER is "false", PIP_PATH and PIP_LOCAL
are removed, and the working directory is a temporary directory, not the
one of R. pip then reports only the packages of the environment.
Every other PIP_* and UV_* variable reaches pip and uv unchanged.
The activation of the R session. R can run in an activated Conda or
pixi environment, or in several nested ones: R installed in a Conda
environment, R started from a shell where conda activate or
pixi shell ran, or R started through a pixi global binary. The
processes that condathis starts do not get that activation, within
the limits below. So a program of R's own environment does not run in
place of one that the environment of the command lacks. Before the
overrides above,
condathis changes the copy of the session's environment this way:
PATHThe binary directories of these Conda prefixes are removed: the
prefixes of CONDA_PREFIX, of every CONDA_PREFIX_<n> and
CONDA_ENV_SHLVL_<n>_CONDA_PREFIX, and the prefix that R itself is
installed in. Only a directory with a conda-meta directory counts
as a prefix. Other entries stay, such as
the condabin directory of conda init and ~/.pixi/bin. One
exception on Windows: a command that is a program of R's own prefix,
such as file.path(R.home("bin"), "Rscript.exe"), gets the binary
directories of that prefix back at the end of its PATH, because it
loads its DLLs from there.
CONDA_PREFIX_<n>, CONDA_ENV_SHLVL_<n>_*, CONDA_EXE,
CONDA_PYTHON_EXE, _CE_CONDA, _CE_M, MAMBA_EXE
Removed. These variables record the activation of the session.
PIXI_PROJECT_*, PIXI_WORKSPACE_*, PIXI_ENVIRONMENT_*,
PIXI_PROMPT, PIXI_IN_SHELL, PIXI_EXE
Removed. Other PIXI_* variables, such as PIXI_HOME, stay.
CONDA_BACKUP_<X>, <X>_CONDA_BACKUP, CONDA_ENV_SHLVL_<n>_<X>
The value of <X> before the activation, saved by the activation
scripts of compiler and other packages, or by pixi. <X> gets that
value back, as the deactivation scripts do: an empty backup of the
first two forms removes <X>. The backups are removed.
conda-meta/state and etc/conda/env_vars.d
A variable that these files of the prefixes above set is removed when the session has exactly that value.
When one of the prefixes above is an environment of pixi global,
a variable that its binaries set when they start is removed when the
session has exactly that value. pixi records them in
bin/trampoline_configuration of its home. R started through such a
binary gets the whole activation of its environment, such as the
compiler variables CC, CFLAGS and CONDA_BUILD_SYSROOT, and a
compiler of the environment of a command would see them.
VIRTUAL_ENV, VIRTUAL_ENV_PROMPT
When VIRTUAL_ENV names a Python virtual environment (a directory
with pyvenv.cfg), both are removed, and its bin directory (on
Windows Scripts) leaves PATH. Activating a virtual environment
sets them, and so does reticulate inside the R session when it uses
one, also through Sys.setenv().
When reticulate has started Python in the R session, the lib
directories that it put in front of LD_LIBRARY_PATH on Linux (of
its python and of the python a virtual environment was made from)
are removed. For a python of a Conda environment, reticulate puts the
binary directories of that environment in front of PATH; they are
removed as those of the prefixes above.
Some changes cannot be undone. A value that an activate.d script of
the session's environment set stays, unless it saved a backup above or
a pixi global binary recorded it, and so does a PATH entry such a
script added. For example, R installed in a Conda environment that has
the compiler packages, and started from a shell where that environment
was activated, passes CC, CFLAGS, CONDA_BUILD_SYSROOT and the
other compiler variables of that environment to the processes it
starts. The binary directory of an environment that no variable names
any more stays too, such as the one of a pixi global binary that started
the shell before another one replaced its CONDA_PREFIX. reticulate
moves the directory of a python that is neither in a virtual nor in a
Conda environment, such as /usr/bin, to the front of PATH; it stays
there. On macOS, when /usr/local/opt/openblas exists, loading
reticulate sets OPENBLAS and, when it is unset, OMP_NUM_THREADS=1;
they stay too.
The startup of R. R also changes its own environment when it starts,
and the processes that condathis starts do not get those changes
either. So an R of the environment of the command never loads packages
built for the R of the session, and a program of the environment never
loads R's libraries or certificates:
R_*, _R_*
Removed, also a variable the user set, such as R_LIBS_USER or
R_PROFILE_USER: only R reads them, and an R that the command
starts sets its own. The R of the session keeps them.
EDITOR, PAGER, MAKE, SED, TAR, LN_S,
CURL_CA_BUNDLE, MSYS2_ENV_CONV_EXCL
Removed when the session has exactly the value that R's startup
gives them (etc/Renviron of R). A value the user set stays, such
as EDITOR=nvim.
LD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH,
DYLD_LIBRARY_PATH
The directories that R put in front (etc/ldpaths of R) are
removed. The directories after them stay.
PATH on WindowsThe Rtools directories that R put in front (R_RTOOLS45_PATH) are
removed. A command finds Rtools only when the PATH that R started
with has it.
condathis learns the values of R's startup by starting R's own
Rscript once per R session, without the user's .Renviron and
.Rprofile. When that fails, only the R_* variables and the Rtools
directories are removed.
With the default activate = TRUE of run(), run_bin() and
run_pipeline(), condathis applies activation variables on top. For
the micromamba backend, these are the variables that a real
micromamba run activation sets. They include the variables from
activate.d scripts shipped by the installed packages. These scripts run
with the command's TMPDIR, user cache and working directory.
condathis records the variables once per environment and R session. It
reuses them until the environment (its packages, its activate.d scripts
or env_vars.d files) or the session's environment variables change. It
starts the command itself. Values that name the command's TMPDIR are
recorded again for every command. Values that name the working directory
are recorded again in another working directory. For other backends, the
backend package sets the activation variables (see register_backend()).
When the PATH of an activation names none of the environment's binary
directories, condathis puts them in front of it.
In both modes and for every backend, a command of run(), run_bin()
and run_pipeline() runs in exactly one activated environment,
whatever the R session runs in: CONDA_SHLVL and MAMBA_SHLVL are
"1", and CONDA_PROMPT_MODIFIER and MAMBA_PROMPT_MODIFIER are
"", whatever the activation set.
With activate = FALSE, run(), run_bin() and run_pipeline() set
this fixed set instead, without any backend code and without the
activate.d scripts and env_vars.d files of the packages:
CONDA_PREFIX, CONDA_DEFAULT_ENV
The environment directory and its name. For an environment given by
env_path(), the name is its directory.
CONDA_SHLVL, MAMBA_SHLVL
Set to "1".
CONDA_PROMPT_MODIFIER, MAMBA_PROMPT_MODIFIER
Set to "".
PATHThe environment's binary directories, in front of the PATH
described above.
TMPDIR and CONDA_ENVS_PATH are the same as with activate = TRUE:
they come from the clean variables above.
On Windows, variable names are matched case-insensitively. An override
replaces any inherited spelling of the same name, such as Path.
condathis uses the first candidate that exists and reports a
compatible version:
The condathis.micromamba_path option.
The CONDATHIS_MICROMAMBA_PATH environment variable.
The binary managed by condathis, see micromamba_bin_path().
A micromamba next to the running R, when R is installed in a Conda
environment.
A micromamba inside CONDA_PREFIX.
A micromamba in the micromamba-env environment of the micromamba
backend, in the envs directory of the condathis data directory.
condathis ignores an environment of that name that another backend
created.
A micromamba on PATH.
A candidate that is a binary exposed by pixi global (a trampoline,
with a trampoline_configuration/<name>.json file next to it) is
replaced by the binary that it starts, the exe of that file, so the
activation of the pixi environment that the trampoline sets never
reaches micromamba. The option and the variable keep the value you
set.
A compatible version is 2.8.1 or newer. When no candidate is
compatible, the first function that needs micromamba calls
install_micromamba(), which downloads the default version into the
managed location. That function says so first, unless its verbose is
"silent", with a message of class condathis_micromamba_downloading.
Queries, such as list_envs(), never download it.
In interactive sessions, condathis shows spinners for every verbose
level except "silent". A session is interactive when
rlang::is_interactive() returns TRUE. install_micromamba() shows
the progress of its download only in interactive sessions, and only
when its verbose is "output" or "full". When another function
installs micromamba because no usable binary was found, the progress
shows only with verbose = "full". Set the rlang_interactive option
to FALSE to turn spinners and progress off in an interactive session.
get_install_dir(), micromamba_bin_path(),
install_micromamba(), with_sandbox_dir(), tools::R_user_dir(),
condathis-conditions
# Redirect all condathis data to temporary directories condathis::with_sandbox_dir({ print(condathis::get_install_dir()$path) })# Redirect all condathis data to temporary directories condathis::with_sandbox_dir({ print(condathis::get_install_dir()$path) })
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).
create_env( ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), channels = "conda-forge", additional_channels = NULL, channel_priority = c("strict", "flexible", "disabled"), platform = NULL, env_file = NULL, overwrite = FALSE )create_env( ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), channels = "conda-forge", additional_channels = NULL, channel_priority = c("strict", "flexible", "disabled"), platform = NULL, env_file = NULL, overwrite = FALSE )
... |
Package match specs (MatchSpec strings), unnamed: character
strings or character vectors, in order. Examples: Or one environment file, given by Any other value aborts with class
|
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
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 ( |
additional_channels |
|
channel_priority |
Channel priority mode: |
platform |
|
env_file |
|
overwrite |
|
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()).
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.
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,"), a
build_number with == ("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.
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.
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.
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()
## Not run: 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" ) }) ## End(Not run)## Not run: 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" ) }) ## End(Not run)
Marks a file as the definition of a Conda environment, such as an
environment YAML file or a lock file. Pass the result in the ... of
create_env(), in place of package specs:
create_env(env_definition("environment.yml"), env_name = "tools").
install_packages() and validate_env() take it too (see Other
functions).
env_definition(path, format = NULL, ...)env_definition(path, format = NULL, ...)
path |
Character string with the path of the file, absolute or
relative to the working directory. |
format |
|
... |
Named options for the backend, such as |
condathis does not read the file. The backend reads it and tells
condathis two things: which format the file has, and whether it is a
request or a lock.
A request, such as an environment YAML file or a list of package specs, is solved when the environment is created. The result depends on the channels and on the day.
A lock, such as an @EXPLICIT file or a conda-lock file, lists exact
packages. It is installed as it is, without a solve, and only for a
platform it lists.
env_definition() makes path absolute against the working directory
at the time of the call, so a later setwd() does not change which file
it refers to. It does not resolve symbolic links, so paths in the file
that are relative to the file, such as -r requirements.txt in a pip:
section, still resolve. create_env() checks that the file exists when
it runs.
An object of class condathis_env_definition: a list with
path (the absolute path), format (NULL or a string) and
options (a named list).
Leave format as NULL and the backend detects the format. Give it
when the file name does not tell, for example for a lock file named
ci.lock. condathis passes format to the backend and never reads
it. These names are a convention: conda uses them for its --format
option. Backends should accept them:
"environment-yaml" (also "cep-24"): an environment YAML file, with
channels: and dependencies:. A request.
"requirements": a text file with one package spec per line. A
request.
"explicit": an @EXPLICIT file, with one package URL per line. A
lock.
"conda-lock-v1": a conda-lock file, version 1. A lock.
"rattler-lock-v6" and "rattler-lock-v7" (also "pixi"): a
pixi.lock file. A lock.
"mambajs-lock-v1": a lock file of mambajs, in JSON. A lock.
The micromamba backend reads environment YAML, requirements, @EXPLICIT,
conda-lock version 1 and mambajs files. It detects the format from the
contents of the file, so the file can have any name, with one exception:
an environment YAML file must have a name that ends in .yml or
.yaml, and not in -lock.yml or -lock.yaml. It does not read
pixi.lock files or directories. For a conda-lock file, it accepts one
option, categories: the package categories to install, "main" by
default, as in categories = c("main", "dev"). A backend aborts for an
option it does not know.
For a lock, create_env() picks the platform from the platforms that
the file lists: platform when it is given, else the native platform of
the backend, else an emulated one (see platform in create_env()).
When the file lists none of these, create_env() aborts with class
condathis_create_env_platform_not_locked (also
condathis_create_env_platform_mismatch) before anything runs.
A lock of noarch packages lists no platform, and installs on any
platform. For an @EXPLICIT or mambajs file, micromamba takes the
platform of each package from its subdir, such as noarch or
linux-64, not from the platform header of the file.
channels, additional_channels and channel_priority cannot be given
with a lock: a lock names its packages by URL. They abort with class
condathis_create_env_conflicting_args. The deprecated env_file
argument of create_env() ignores them, as in 0.1.4. A lock that lists packages but
gives an empty environment aborts with class
condathis_create_env_failed.
When the backend reports the packages of a lock, as micromamba does for
@EXPLICIT, conda-lock and mambajs files, an existing environment is
compared with them: the same names, versions and build strings, none
missing and none more, for the platform of the lock. Packages that pip
installed are left out. create_env(overwrite = FALSE) then keeps an
environment that has exactly those packages, and
validate_env(env_definition(<lock>), env_name = ...) returns TRUE.
install_packages() installs the packages of a request into an
existing environment, as micromamba install -f <file> does. It
aborts for a lock, with class
condathis_install_packages_unsupported_definition: create the
environment again with create_env(..., overwrite = TRUE).
validate_env() compares an environment with a lock (see Locks).
It aborts for a request, with class
condathis_validate_env_unsupported_definition: a request depends on
the channels and on the day.
With method = "auto", create_env() creates a new environment with
the first available backend in condathis.backend_priority order that
does not say it cannot read the file. An explicit method, or an
existing environment, keeps its backend.
Other environments:
create_env(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
remove_env(),
validate_env()
condathis::env_definition("environment.yml") condathis::env_definition("ci.lock", format = "conda-lock-v1") condathis::env_definition("conda-lock.yml", categories = c("main", "dev")) ## Not run: condathis::with_sandbox_dir({ # An environment YAML file shipped with condathis. env_file <- system.file("extdata", "stat-env.yml", package = "condathis") condathis::create_env( condathis::env_definition(env_file), env_name = "stat-env" ) }) ## End(Not run)condathis::env_definition("environment.yml") condathis::env_definition("ci.lock", format = "conda-lock-v1") condathis::env_definition("conda-lock.yml", categories = c("main", "dev")) ## Not run: condathis::with_sandbox_dir({ # An environment YAML file shipped with condathis. env_file <- system.file("extdata", "stat-env.yml", package = "condathis") condathis::create_env( condathis::env_definition(env_file), env_name = "stat-env" ) }) ## End(Not run)
Checks whether an environment name is present in the environments managed
by condathis.
env_exists(env_name = "condathis-env", method = "auto", verbose = "silent")env_exists(env_name = "condathis-env", method = "auto", verbose = "silent")
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend to query. |
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
env_exists() is a query: it never creates an environment. When
env_name has no directory under a backend's data directory, as on a new
data directory, env_exists() returns FALSE. It does not start or
install micromamba.
When no micromamba binary is installed, the micromamba backend reads
the envs directory of its data directory and the package records in
conda-meta/ instead. It never installs micromamba.
TRUE when a queried backend reports the environment. FALSE
when every queried backend reports it absent. When the query fails for
the backend that method names, env_exists() aborts with class
condathis_env_exists_failed (also condathis_backend_error). With
method = "auto", a backend whose query fails is skipped, with a
warning of class condathis_backend_query_failed, and env_exists()
aborts only when every backend fails.
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
remove_env(),
validate_env()
condathis::with_sandbox_dir({ # A query: it creates nothing and needs no micromamba condathis::env_exists("non-existent-env") }) ## Not run: 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 the environment condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # Check if the environment exists print(condathis::env_exists("polyglot-env")) #> [1] TRUE # Check for a non-existent environment condathis::env_exists("non-existent-env") #> [1] FALSE }) ## End(Not run)condathis::with_sandbox_dir({ # A query: it creates nothing and needs no micromamba condathis::env_exists("non-existent-env") }) ## Not run: 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 the environment condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # Check if the environment exists print(condathis::env_exists("polyglot-env")) #> [1] TRUE # Check for a non-existent environment condathis::env_exists("non-existent-env") #> [1] FALSE }) ## End(Not run)
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().
env_path(path)env_path(path)
path |
Character string with the path of the environment
directory (the prefix), absolute or relative to the working directory.
|
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.
An object of class condathis_env_path, holding the absolute
path.
run(), run_bin(), run_pipeline(), run_step()
Other environments:
create_env(),
env_definition(),
env_exists(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
remove_env(),
validate_env()
condathis::env_path("/opt/conda/envs/shared-tools") ## Not run: 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) }) ## End(Not run)condathis::env_path("/opt/conda/envs/shared-tools") ## Not run: 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) }) ## End(Not run)
Returns the absolute path where an environment is expected under the data directory of its backend. It returns the path even if the environment does not exist yet.
get_env_dir(env_name = "condathis-env", method = "auto")get_env_dir(env_name = "condathis-env", method = "auto")
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
Looks up which registered backend owns env_name, and creates the
backend's data directory when needed. It creates no environment. When
env_name has no directory yet, it does not start or install
micromamba.
An fs_path: the absolute path of the environment directory.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
install_packages(),
list_envs(),
list_packages(),
remove_env(),
validate_env()
condathis::with_sandbox_dir({ # Get the default environment directory print(condathis::get_env_dir()) #> <data dir>/R/condathis/envs/condathis-env # Get the directory for a specific environment condathis::get_env_dir("my-env") #> <data dir>/R/condathis/envs/my-env })condathis::with_sandbox_dir({ # Get the default environment directory print(condathis::get_env_dir()) #> <data dir>/R/condathis/envs/condathis-env # Get the directory for a specific environment condathis::get_env_dir("my-env") #> <data dir>/R/condathis/envs/my-env })
Returns the data directory of each registered backend. The
"micromamba" backend uses the condathis data directory,
tools::R_user_dir("condathis", "data") (see condathis-options for
the variables that move it). Every other backend uses the directory of
its name inside it, backend_root_dir(), unless it chooses its own. An
example is <condathis data directory>/rattler for the "rattler"
backend.
get_install_dir(method = "auto")get_install_dir(method = "auto")
method |
Character string naming the backend to report. |
On macOS, when neither R_USER_DATA_DIR nor XDG_DATA_HOME is set, the
condathis data directory is ~/.local/share/R/condathis, a path without
spaces. micromamba run can fail on paths that contain spaces.
The data directories of the other backends that use backend_root_dir()
are inside the condathis data directory. So deleting it deletes their
environments and caches too. Each backend keeps its environments in the
envs directory of its own data directory. To remove everything that
condathis installed, see Removing everything in clean_cache().
micromamba adds each environment that it creates to
~/.conda/environments.txt (in %USERPROFILE% on Windows), the list of
environments that conda and mamba share. It creates that file when it
is missing. To leave the file alone, condathis runs
micromamba create, micromamba env list and micromamba env remove
with the home/ directory of the data directory as their home.
create_env() still runs micromamba with your home directory when
micromamba needs something from there. It then adds the environment to
your list. This happens for channel credentials that you saved (with
micromamba auth login, an anaconda-client token, or a .netrc
file), for an environment file (env_definition()) that names your
home directory (~/, $HOME), and for one that installs pip packages
when pip or uv would read a file from your home directory: a pip
configuration file (~/.pip/pip.conf, ~/.config/pip/pip.conf, on
macOS also ~/Library/Application Support/pip/pip.conf, on Windows
~\pip\pip.ini), a uv configuration file (~/.config/uv/uv.toml) or
uv credentials (uv auth login), or when a keyring program is on
PATH. Listing environments never changes the file. remove_env()
deletes only the line of the environment it removed. A ~ at the start
of a channel, of a package path and of the path of an environment file
always means your own home directory.
The pip that installs the pip packages of an environment file keeps its
cache in the cache/ directory of the data directory on Linux, which
clean_cache() deletes. On macOS and Windows, it keeps its cache in
your own user cache (~/Library/Caches/pip,
%LOCALAPPDATA%\pip\Cache).
A data frame (a tibble) with one row per backend covered by
method, and the character columns backend and path. path is
the real, absolute path of the data directory of the backend, which is
created when it does not exist yet. get_install_dir() creates no
environment and does not install micromamba. When the backend that
method names fails, get_install_dir() aborts with class
condathis_get_install_dir_failed (also condathis_backend_error).
With method = "auto", a backend that fails is skipped, with a
warning of class condathis_backend_query_failed.
backend_root_dir(), condathis-options
Other setup:
clean_cache(),
get_sys_arch(),
install_micromamba(),
micromamba_bin_path(),
with_sandbox_dir()
condathis::with_sandbox_dir({ # One row per backend: its name and its data directory, # <data dir>/R/condathis for micromamba print(condathis::get_install_dir()) })condathis::with_sandbox_dir({ # One row per backend: its name and its data directory, # <data dir>/R/condathis for micromamba print(condathis::get_install_dir()) })
Returns the operating system and the CPU architecture that the running
R reports with base::Sys.info(), as a single string,
"<OS>-<architecture>". install_micromamba() uses it to choose the
micromamba build.
get_sys_arch()get_sys_arch()
A character string such as "Linux-x86_64", "Linux-aarch64",
"Linux-riscv64", "Darwin-x86_64" or "Darwin-arm64". On Windows it is
"Windows-aarch64" for a native ARM64 build of R. It is
"Windows-x86-64" for an x64 build, also when that build runs through
x64 emulation on an ARM64 PC.
Other setup:
clean_cache(),
get_install_dir(),
install_micromamba(),
micromamba_bin_path(),
with_sandbox_dir()
condathis::get_sys_arch()condathis::get_sys_arch()
Downloads the micromamba binary that condathis uses and installs it
in the condathis data directory, at the path that
micromamba_bin_path() returns. The functions that need micromamba call
it when no usable binary is found (see micromamba discovery in
condathis-options), for the default version. They first show a message
of class condathis_micromamba_downloading that names the version and
the path, unless their verbose is "silent". You need to call it only
to choose the version, or to install micromamba ahead of time.
install_micromamba( micromamba_version = "2.10.0-0", timeout = 3600, download_method = "auto", force = FALSE, verbose = c("output", "silent", "cmd", "spinner", "full"), timeout_limit = NULL )install_micromamba( micromamba_version = "2.10.0-0", timeout = 3600, download_method = "auto", force = FALSE, verbose = c("output", "silent", "cmd", "spinner", "full"), timeout_limit = NULL )
micromamba_version |
Character string with the micromamba version,
in the format
With |
timeout |
Numeric download timeout in seconds, a single
non-negative number. |
download_method |
Character string with the download method of
|
force |
Logical value. |
verbose |
Character string that controls the console output. One
of
|
timeout_limit |
Deprecated. Use |
The binary is the build for the platform of the running R (see
get_sys_arch()): linux-64, linux-aarch64, linux-ppc64le,
linux-riscv64, osx-64, osx-arm64, win-64 or win-arm64. On
another platform, install_micromamba() aborts with class
condathis_micromamba_not_available_for_arch.
linux-riscv64 has builds from micromamba 2.9.0 on, so an older
version aborts there with the same class. The GitHub releases have them
from 2.10.0-0 on: 2.9.0 comes from the conda-forge mirrors, and its
checksum cannot be checked (see below).
A native ARM64 R on Windows gets win-arm64. An x64 R on an ARM64 PC
gets win-64, which runs through x64 emulation. Every R of a user
shares the installed binary. So on an ARM64 PC, the binary installed
first stays until you replace it, for example with force = TRUE.
Either binary works with both builds of R: micromamba builds
environments for its own platform.
install_micromamba() tries the compressed archive first, from the
micromamba releases on GitHub, then from the conda-forge channel on
anaconda.org and prefix.dev. It extracts the archive with R's internal
tar, so no system tar or bzip2 is needed. When every archive
fails, it downloads the standalone binary from GitHub. A mirror fails
when the download fails, or when the file does not extract, does not
run, or does not match the SHA256 checksum published with the release.
Then it tries the next mirror. It replaces an installed binary only with
a download that passed these checks, also with force = TRUE.
The checksum is downloaded from the GitHub release when the binary is
installed. When it cannot be downloaded or read, or the SHA256 hash of
the binary cannot be computed, install_micromamba() still installs the
binary, so that mirrors work when GitHub cannot be reached, but warns
with class condathis_install_micromamba_checksum_unavailable. It warns
for every verbose level except "silent", also when a function that
needs micromamba installs it. A checksum that does not match warns with
class condathis_install_micromamba_checksum_mismatch, also when
verbose is "silent", and that binary is not installed. The hash is
computed with tools::sha256sum() on R 4.5.0 or later, else with the
digest package when it is installed, else with the sha256sum or
shasum program, or on Windows certutil.
The path of the micromamba binary, an fs_path, invisibly: the
path that micromamba_bin_path() returns. A failed download aborts
with class condathis_install_micromamba_download_failed.
Other setup:
clean_cache(),
get_install_dir(),
get_sys_arch(),
micromamba_bin_path(),
with_sandbox_dir()
## Not run: condathis::with_sandbox_dir({ # Install the default version of micromamba condathis::install_micromamba() # Install a specific version (2.8.1 or newer): it replaces a binary of # another version condathis::install_micromamba(micromamba_version = "2.9.0-0") # Without `micromamba_version`, the installed binary is kept unless # `force = TRUE` condathis::install_micromamba(force = TRUE) }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # Install the default version of micromamba condathis::install_micromamba() # Install a specific version (2.8.1 or newer): it replaces a binary of # another version condathis::install_micromamba(micromamba_version = "2.9.0-0") # Without `micromamba_version`, the installed binary is kept unless # `force = TRUE` condathis::install_micromamba(force = TRUE) }) ## End(Not run)
Installs packages into an existing environment, from package specs or
from an environment file given by env_definition().
install_packages() creates the default environment "condathis-env",
empty, when it does not exist. Any other environment that does not exist
aborts with class condathis_install_packages_env_not_found (also
condathis_env_not_found). Create it with create_env() first.
install_packages( ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), channels = "conda-forge", additional_channels = NULL, channel_priority = c("strict", "flexible", "disabled") )install_packages( ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), channels = "conda-forge", additional_channels = NULL, channel_priority = c("strict", "flexible", "disabled") )
... |
Package match specs (MatchSpec strings) to install, unnamed:
character strings or character vectors, in order. Examples:
Or one environment file that is solved, given by
Package specs and a definition together, or two definitions, abort
with class
Invalid specs abort with these classes:
|
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
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 ( The |
additional_channels |
|
channel_priority |
Channel priority mode: |
install_packages() installs packages for the platform of the
environment, with every backend. That platform is the one the environment
was created for (see platform in create_env()). Otherwise, on Apple
Silicon and on Windows, it is the platform of the environment's packages
that are not noarch.
An environment with no packages other than noarch ones, such as a new
"condathis-env", gets the emulation fallback of create_env() instead.
Packages that cannot be installed for the native platform then use an
emulated platform, when they can be installed there. That platform is
"osx-64" on Apple Silicon when Rosetta 2 is running. On Windows with a
backend that solves for "win-arm64", such as the win-arm64
micromamba, it is "win-64". Later installs then use the same platform.
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. stdout, stderr and pid are NA when the
backend reports none, and pid always is with micromamba.
A backend failure aborts with class condathis_install_packages_failed
(also condathis_backend_error), with the backend's error as the
parent.
micromamba runs the link scripts of packages. A backend that does not
makes install_packages() warn with class
condathis_install_packages_link_scripts_skipped (also
condathis_link_scripts_skipped). The warning names the packages.
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.
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
list_envs(),
list_packages(),
remove_env(),
validate_env()
## Not run: 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" ) # Install `polyglot` into an existing, empty environment. condathis::create_env(env_name = "my-env") condathis::install_packages( "polyglot", env_name = "my-env", channels = channel ) condathis::create_env( "bioconda::fastqc", env_name = "fastqc-env" ) # Add `python` to the `fastqc-env` environment, for scripts that read # the reports of `fastqc`. Keep unrelated tools in separate # environments, so that their dependencies cannot conflict. # `bioconda` is passed again, because `fastqc` came from it: leaving out # a channel the environment was built from warns. `conda-forge` comes # first: with strict channel priority, the first channel wins. condathis::install_packages( "python", env_name = "fastqc-env", channels = c("conda-forge", "bioconda") ) }) ## End(Not run)## Not run: 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" ) # Install `polyglot` into an existing, empty environment. condathis::create_env(env_name = "my-env") condathis::install_packages( "polyglot", env_name = "my-env", channels = channel ) condathis::create_env( "bioconda::fastqc", env_name = "fastqc-env" ) # Add `python` to the `fastqc-env` environment, for scripts that read # the reports of `fastqc`. Keep unrelated tools in separate # environments, so that their dependencies cannot conflict. # `bioconda` is passed again, because `fastqc` came from it: leaving out # a channel the environment was built from warns. `conda-forge` comes # first: with strict channel priority, the first channel wins. condathis::install_packages( "python", env_name = "fastqc-env", channels = c("conda-forge", "bioconda") ) }) ## End(Not run)
Returns a data frame of the environments under the data directory of
each registered backend. It leaves out environments that condathis does
not manage.
list_envs(method = "auto", verbose = "silent")list_envs(method = "auto", verbose = "silent")
method |
Character string naming the backend to query. |
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
list_envs() is a query: it never creates an environment. On a new data
directory, with no environment yet, it returns a data frame with no rows.
It does not start or install micromamba.
When no micromamba binary is installed, the micromamba backend reads
the envs directory of its data directory and the package records in
conda-meta/ instead. It never installs micromamba.
A data frame (a tibble) with one row per environment and the
columns backend (chr), env_name (chr) and path (chr). The
rows follow the backend order of method. When the listing fails for
the backend that method names, list_envs() aborts with class
condathis_list_envs_failed (also condathis_backend_error). With
method = "auto", list_envs() skips a backend whose listing fails
and warns with class condathis_backend_query_failed. It aborts only
when every backend fails.
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_packages(),
remove_env(),
validate_env()
condathis::with_sandbox_dir({ # No environment yet: a data frame with no rows print(condathis::list_envs()) }) ## Not run: 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 environments condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) condathis::create_env(env_name = "empty-env") # List environments print(condathis::list_envs()$env_name) #> [1] "empty-env" "polyglot-env" }) ## End(Not run)condathis::with_sandbox_dir({ # No environment yet: a data frame with no rows print(condathis::list_envs()) }) ## Not run: 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 environments condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) condathis::create_env(env_name = "empty-env") # List environments print(condathis::list_envs()$env_name) #> [1] "empty-env" "polyglot-env" }) ## End(Not run)
Returns the packages installed in a Conda environment, as a data frame.
list_packages(env_name = "condathis-env", method = "auto", verbose = "silent")list_packages(env_name = "condathis-env", method = "auto", verbose = "silent")
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
list_packages() is a query: it never creates an environment, also not
the default "condathis-env". A missing environment aborts. When the
environment has no directory, as on a new data directory,
list_packages() does not start or install micromamba.
When no micromamba binary is installed, the micromamba backend reads
the envs directory of its data directory and the package records in
conda-meta/ instead. It never installs micromamba.
A data frame (a tibble) with one row per installed package, returned visibly. Six columns are guaranteed on every backend:
name (chr): the package name.
version (chr): the package version.
build_number (int): the build number.
build_string (chr): the build string.
channel (chr): a channel name or URL.
platform (chr): the platform subdirectory, such as "linux-64" or
"noarch".
The list includes the packages that pip or uv installed into the
environment, with every backend. It shows them as micromamba does:
channel "pypi", build string "pypi_0", build number 0, and the
platform as pip reports it, such as "linux-x86_64". Only the
environment's own site-packages counts, not the user's site
directory or PYTHONPATH.
Other columns vary by backend. Do not rely on them in code that must
work with every backend. The "micromamba" backend today also includes
base_url, dist_name, md5, sha256 and url.
list_packages() shows the password and the token of a channel URL as
*****, as micromamba does (https://user:*****@host/channel,
https://host/t/*****/channel).
It aborts with these classes:
condathis_list_packages_env_not_found (also
condathis_env_not_found): a missing environment.
condathis_list_packages_failed (also condathis_backend_error): a
failed listing. A listing without the six columns also has the class
condathis_backend_invalid_return.
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
remove_env(),
validate_env()
## Not run: 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 with `polyglot` condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # List the packages of the environment `polyglot-env` dat <- condathis::list_packages("polyglot-env") print(dat[, c("name", "version", "channel")]) }) ## End(Not run)## Not run: 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 with `polyglot` condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # List the packages of the environment `polyglot-env` dat <- condathis::list_packages("polyglot-env") print(dat[, c("name", "version", "channel")]) }) ## End(Not run)
Returns the names of every backend registered with register_backend(),
available on this system or not. Each one is a valid method value of
every condathis function that takes method, besides "auto". The
built-in "micromamba" backend is always registered.
list_registered_backend_names()list_registered_backend_names()
A backend whose package condathis knows, such as "rattler" of the
rattlerthis package, is also a valid method value when its package
is installed but not loaded yet. condathis loads the package on first
use (see Registering from a backend package in register_backend()).
It is listed here once it is loaded. The error for an invalid method
value names these backends too.
A sorted character vector of registered backend names.
Other backends:
backend_root_dir(),
register_backend(),
unregister_backend()
condathis::list_registered_backend_names()condathis::list_registered_backend_names()
Returns the path of the micromamba executable that
install_micromamba() installs, in the condathis data directory (see
get_install_dir()). It is the third candidate of micromamba
discovery in condathis-options, after the condathis.micromamba_path
option and the CONDATHIS_MICROMAMBA_PATH variable.
micromamba_bin_path()micromamba_bin_path()
An fs_path, the full path of the executable:
micromamba/bin/micromamba in the condathis data directory, or
micromamba/Library/bin/micromamba.exe on Windows. It does not check
that a file exists there. Like get_install_dir(), it creates the
condathis data directory when it is missing. Use fs::file_exists() on
the result to check that the binary is present, or
install_micromamba() to install it.
Other setup:
clean_cache(),
get_install_dir(),
get_sys_arch(),
install_micromamba(),
with_sandbox_dir()
condathis::with_sandbox_dir({ # The path where condathis installs micromamba print(condathis::micromamba_bin_path()) })condathis::with_sandbox_dir({ # The path where condathis installs micromamba print(condathis::micromamba_bin_path()) })
Splits an output stream of a run(), run_bin() or run_pipeline()
result into lines.
parse_output( res, stream = c("stdout", "stderr", "both", "plain"), trim = FALSE )parse_output( res, stream = c("stdout", "stderr", "both", "plain"), trim = FALSE )
res |
A |
stream |
Character string selecting the output source:
Other values abort with class |
trim |
Logical. Whether to remove whitespace at the start and end of
each line, and blank lines at the start and end of the output. Defaults
to |
Lines end at a line feed, a carriage return and line feed pair, or a
carriage return alone, so the result is the same on every operating
system. parse_output() removes the line ends, and a line end at the end
of the output does not start one more, empty line. It keeps the rest of
the text as the command wrote it: spaces and tabs at the start and end of
lines, and blank lines. Empty output gives character(0).
trim = TRUE also removes whitespace at the start and end of each line,
and blank lines at the start and end of the output. This is useful for
a single value, such as a version string. It changes tab-separated
output with empty first or last fields, and indented text such as YAML.
A character vector with one line per element, without line
ends. character(0) for empty output. A res that cannot be read
aborts with class condathis_parse_output_invalid_res (also
condathis_invalid_res), and a raw stream with
condathis_parse_output_binary_stream.
Other commands:
run(),
run_bin(),
run_pipeline(),
run_step()
# A list with the output fields of a `run()` result res <- list( stdout = "line1\nline2\nline3\n", stderr = "error1\nerror2\n" ) # Parse the standard output parse_output(res, stream = "stdout") # Parse the standard error parse_output(res, stream = "stderr") # Merge both parse_output(res, stream = "both") # Parse plain text plain_text <- "This is line one.\nThis is line two.\nThis is line three." parse_output(plain_text, stream = "plain") # Whitespace is kept: the empty first field of this tab-separated line # stays in place parse_output("\tchr1\t100\n", stream = "plain") # Remove it when only the text matters parse_output(" 2.9.0 \n\n", stream = "plain", trim = TRUE)# A list with the output fields of a `run()` result res <- list( stdout = "line1\nline2\nline3\n", stderr = "error1\nerror2\n" ) # Parse the standard output parse_output(res, stream = "stdout") # Parse the standard error parse_output(res, stream = "stderr") # Merge both parse_output(res, stream = "both") # Parse plain text plain_text <- "This is line one.\nThis is line two.\nThis is line three." parse_output(plain_text, stream = "plain") # Whitespace is kept: the empty first field of this tab-separated line # stays in place parse_output("\tchr1\t100\n", stream = "plain") # Remove it when only the text matters parse_output(" 2.9.0 \n\n", stream = "plain", trim = TRUE)
Adds a backend: the engine that creates Conda environments and runs
commands in them. condathis has one built-in backend, "micromamba".
Another package can provide a backend and register it from its
.onLoad() (see Registering from a backend package). The backend's
name is then a valid method value of every condathis function that
takes method, and method = "auto" can select it.
register_backend(name, backend, call = rlang::caller_env())register_backend(name, backend, call = rlang::caller_env())
name |
Character string, the backend name that users pass as
|
backend |
The backend object: a list of the backend functions, with its own class. See The backend object. |
call |
The environment reported as the caller in errors, for calls
from another package's |
backend is a list of backend functions, with its own class: the three
required functions described below, and any of the optional ones.
condathis supplies a default for every optional function that the list
leaves out. register_backend() checks the list, then registers each
function as an S3 method of the condathis generic of the same name,
from inside the condathis namespace. The backend package needs no S3
registrations in its NAMESPACE.
name, invisibly. Aborts with these classes:
condathis_backend_invalid_name: a name that breaks the rules above.
condathis_backend_reserved_name (also
condathis_backend_invalid_name): a reserved name.
condathis_backend_root_conflict (also
condathis_backend_invalid_name): a name whose entry in the
condathis data directory is not a directory.
condathis_backend_name_conflict (also
condathis_backend_invalid_name): a name that differs only in case
from another backend name.
condathis_backend_class_conflict: another registered name uses the
same first class.
condathis_backend_contract_violation: a backend object that breaks
the contract. The error names the missing functions or arguments.
Every error also has the class condathis_error, and the name errors
have condathis_invalid_arg.
This extension API is experimental. condathis 0.2.0 defines the
contract, designed together with a second backend package
(rattlerthis). The API may still change in breaking ways between
0.x releases. State the condathis version that you developed
against, for example as condathis (>= 0.2.0) in Imports.
Build the backend as:
structure(
list(<the functions>),
class = c("condathis_backend_<name>", "condathis_backend")
)
S3 dispatch keys on the first class, so it must be unique to the
backend. It must not be "condathis_backend", "default", "list" or
"data.frame": methods for those classes would also catch objects that
are not this backend. The element names are the names of the functions
below. The object must have backend_create_env, backend_install and
backend_resolve_run. Each other function is optional: an element that
is missing or NULL gets the default of condathis. Each function must
accept every argument of its signature by name, or have a ...
argument. register_backend() checks the class and the three required
functions. It checks that each other element of the contract is a
function or NULL. It also checks the rule of the next paragraph and
the arguments of the functions that are present. Extra elements are
ignored.
An object that has its own backend_get_install_dir() must also have
its own backend_get_env_dir(), backend_list_envs() and
backend_env_exists(). An object that has its own
backend_get_env_dir() must also have its own backend_list_envs() and
backend_env_exists(). Their defaults look for environments in
<backend_root_dir(name)>/envs, not where the backend keeps them.
Each backend has a root, its data directory, which get_install_dir()
reports. The root of the "micromamba" backend is the condathis data
directory, tools::R_user_dir("condathis", "data"). The root of every
other backend is the directory of its name inside it,
backend_root_dir(): for example <condathis data directory>/rattler.
So the root of a backend can lie inside the root of micromamba. The
names of the entries of the condathis data directory are reserved (see
name). Each backend has its own environment directory, <root>/envs,
and its own package caches, and never uses those of another backend.
condathis owns <root>/conda-pkgs in the root of every backend (see
Child processes), so a backend must not use that name.
with_sandbox_dir() moves the condathis data directory, and with it
every root that backend_root_dir() gives.
condathis passes backend first and every other argument by name. It
checks every value before it calls a backend function. verbose is
always one of the five strings, so the defaults of the signatures below
are never used. The values are:
backend: the registered backend object.
env_name: a valid environment name, as described for the env_name
argument of create_env(). It is a single directory name, never a
path.
packages: a character vector of package match specs, such as
"python>=3.12", without NA or "". backend_create_env() gets
NULL when the request has no packages: an empty environment, or one
built from env_file. backend_install() gets NULL when it
installs from env_file.
env_file: NULL, or the absolute path of an existing environment
file (or directory) from an env_definition(). When it is set,
packages is NULL.
definition: the env_definition() object that env_file comes
from, a list with path (the same path as env_file), format
(NULL or a string) and options (a named list). It came after the
first functions of version 2 of this contract, so it is not in the
signatures below, and a function written without it keeps working.
condathis passes it only to a function that has a definition
argument (or ...), and only when env_file is set. condathis never reads format or
options: the backend does. A backend function without the argument
gets only env_file. Then a definition with a format or options
aborts before any call, with class
condathis_create_env_unsupported_definition or
condathis_install_packages_unsupported_definition (also
condathis_backend_unsupported).
channels: a non-empty character vector of channel names or URLs,
without NA or "", in priority order.
additional_channels: NULL, or a character vector like channels.
These channels come after channels.
channel_priority: "strict", "flexible" or "disabled".
platform: NULL, or one known conda platform (subdir) name, such as
"linux-64" or "osx-arm64" (see platform in create_env()). It
can still be a platform that the backend does not support. NULL
means the native platform of the backend.
overwrite: TRUE or FALSE.
verbose: one of "output" (show the backend's output), "silent"
(show nothing), "cmd" (show the command line), "spinner" (show
only progress) or "full" (show everything, also the backend's own
log). It is never a logical or a vector. The probes and listings that
condathis uses to choose a backend get "silent". condathis prints
its own messages, such as "Environment x successfully created.", so the
backend must not print them again.
cmd: a single, non-empty string. args: a character vector.
base_env: a named character vector, the environment of the command
before activation (see backend_resolve_run()).
env_dir: the absolute path of an existing directory with a
conda-meta directory, in its real form (see
backend_resolve_run_in_dir()).
timeout: a positive number of seconds. It can also be Inf (no
limit) for backend_resolve_run() and backend_resolve_run_in_dir().
create_env(), install_packages() and remove_env() hold the lock of
the environment name (see Other R sessions in create_env()). They
hold it while they call backend_create_env(), backend_install() or
backend_remove_env(), and during the existence checks before them. So
no other R session that uses condathis changes the environment
meanwhile, with any backend. They also hold the lock of the package
caches, shared. clean_cache() holds it exclusive while it calls
backend_clean_cache(). So no create or install of another R session
runs while caches are deleted. A backend needs no lock of its own
against those sessions.
backend_create_env(backend, packages = NULL, env_file = NULL, env_name = "condathis-env", channels = "conda-forge", channel_priority = c("strict", "flexible", "disabled"), additional_channels = NULL, platform = NULL, overwrite = FALSE, verbose = c("output", "silent", "cmd", "spinner", "full")) creates
the environment. It can also take the optional argument
definition = NULL (see What condathis passes). Its directory is
the one that backend_get_env_dir() returns, and condathis calls it
only when that directory does not exist. That is the case for a new
environment. It is also the case with
overwrite = TRUE, after condathis moved the existing environment
aside or deleted a directory that was not an environment (one left by
a failed create). When the call fails, condathis deletes what it left
and moves the old environment back. A call fails also when it returns a
non-zero status or an invalid link_scripts_skipped (see Results).
So a misspelled spec with overwrite = TRUE does not cost the user the
environment. overwrite tells the backend which of the two cases
applies. With env_file, build the environment from that file (read
definition for its format and options, when the function takes
it). With
platform, build it for that platform. The platform can be one that
condathis chose because the request does not solve for the native
platform of the backend (see backend_can_solve()). After a successful
call, condathis writes <env_dir>/.condathis/backend.json. It uses
this marker as a cross-check, and the marker records the platform when
one was given or chosen.
condathis moves aside or deletes only the directory<backend_get_install_dir()>/envs/<env_name>. For a backend whose
backend_get_env_dir() returns another directory, create_env()
cannot replace an existing environment, or delete a directory left by
a failed create. It aborts with condathis_create_env_failed, whose
parent has the class condathis_unsafe_env_dir_move or
condathis_unsafe_env_dir_delete.
condathis keeps the environment that it replaces in the directory<backend_get_install_dir()>/envs/#trash until the backend succeeded.
No environment can have that name, so backend_list_envs() must leave
that directory out.
backend_install(backend, packages, env_name = "condathis-env", channels = "conda-forge", channel_priority = c("strict", "flexible", "disabled"), additional_channels = NULL, platform = NULL, verbose = c("output", "silent", "cmd", "spinner", "full")) installs
packages into the existing environment env_name, solving for
platform. condathis passes the platform recorded for the
environment: the one in its marker or its .mambarc. On Apple Silicon
and on Windows, condathis can choose an emulated platform (see
backend_can_solve()). There it also reads the platform of the
package records of an environment without a recorded one. For an
environment without packages of a platform, it passes the platform
that it would choose for a new environment. Otherwise, platform is
NULL. It must not create a missing environment.
It can also take the optional arguments env_file = NULL and
definition = NULL. With env_file, install the packages that the
file requests, solved
together with the packages of the environment, as micromamba install -f does. install_packages() passes a file only when
backend_describe_definition() did not say that it is a lock (or that
the backend cannot read it). A function that takes neither argument
cannot install from a file, and
install_packages() then aborts before any call with class
condathis_install_packages_unsupported_definition. A function that
takes env_file but not definition gets only the path, as
backend_create_env() does.
backend_resolve_run(backend, cmd, args = character(0L), env_name = "condathis-env", verbose = "silent", base_env = NULL, timeout = Inf) describes, without running cmd, how to run cmd
with args in the activated environment. base_env is the
environment of the command before any activation: the session's
environment with the changes of Child processes, the activation of
the R session undone included. Compute the activation against it, not
against the environment of the R session.
condathis always passes it. timeout is the number of seconds the
function may take: what is left of the timeout of run(),
run_bin() or run_pipeline(), or Inf. If the function runs code
to compute the activation, such as the activate.d scripts of the
environment, that code can hang. The function should stop it when the
time runs out, and signal an error. When the time ran out,
condathis reports a timeout for the call (timeout = TRUE, status
-9), whatever the function returned or signaled. It does not start
the command. timeout is the one argument a function may leave out.
Then condathis does not pass it, and can report the timeout only
once the function returned.
The function returns list(command, args, env, dir):
command: a single string, the program to start: an absolute path,
or a bare name. run(), run_bin() and run_pipeline() start a
bare name the same way for every backend. On Linux and macOS, it is
looked up on the PATH of the command, after env is applied. On
Windows, as in cmd.exe, the working directory of the command comes
first, and a name without an extension is looked up with the
extensions of PATHEXT. A bare name that is found nowhere fails to
start, with status 127.
args: a character vector, or NULL. It replaces the user's
arguments, so it must contain them.
env: NULL, or a named character vector (not a list) of
activation variables. Each entry replaces the variable of the same
name in the environment of the command, PATH included. An NA
entry removes the variable, for a variable that the activation
unsets. When the PATH that results names none of the binary
directories of the environment, condathis puts them in front of
it. CONDA_SHLVL, MAMBA_SHLVL and the prompt modifiers are always
"1", "1", "" and "", whatever env sets.
dir: NULL to keep R's working directory, or the path of an
existing directory to run the command in.
condathis calls it only with activate = TRUE (the default of
run(), run_bin() and run_pipeline()). With activate = FALSE,
no backend function describes the command: condathis sets a fixed
activation itself (see condathis-options). It calls it only for an
environment that this backend reported as existing. It never calls it
for an env_path() environment (see backend_resolve_run_in_dir()).
A value that breaks these rules aborts with
condathis_backend_resolve_run_invalid.
The defaults treat the environments of a backend as conda prefixes in
<backend_root_dir(name)>/envs. A directory there with
conda-meta/history is an environment, and the conda-meta/*.json
files are its package records.
backend_get_install_dir(backend) returns the backend's root: the
absolute path of an existing directory, in its real form
(fs::path_real()). Paths then compare equal where a temporary
directory is a symbolic link (macOS). Create the directory when it is
missing. Default: backend_root_dir(), created when missing.
backend_get_env_dir(backend, env_name = "condathis-env") returns the
absolute path of the environment directory (its prefix): the directory
that backend_create_env() creates. It returns the path also for an
environment that does not exist yet, and it must not create anything.
Default: <backend_root_dir(name)>/envs/<env_name>.
backend_list_envs(backend, verbose = "silent") returns the names of
this backend's environments: a character vector without NA or
duplicates. Names of the vector are dropped. It returns character(0)
when there are none, also when the backend's root does not exist yet.
It is read only: it must not create anything, and it should not
install or download anything. Default: the directories in
<root>/envs that have conda-meta/history, without symbolic links
and without directories whose real path is elsewhere, as
micromamba env list reports them.
backend_env_exists(backend, env_name, verbose = "silent") returns
TRUE or FALSE: whether env_name is an environment of this
backend. It must agree with backend_list_envs(). condathis calls it
for every registered backend on every call that names an environment,
whatever method is, to find the backend that owns the environment.
So it must be cheap and must not create anything. Avoid processes and
downloads. Report only the environments in this backend's own root:
when two backends report the same name, condathis aborts with
condathis_backend_ambiguous_env unless method names one of them.
Default: FALSE when <root>/envs/<env_name> is not a directory,
else whether backend_list_envs() lists env_name (a file system
that ignores case opens the directory for every spelling).
backend_list_packages(backend, env_name = "condathis-env", verbose = "silent") returns a data frame (a tibble is fine) with one
row per installed package and at least these columns: name,
version, build_string, channel and platform (character), and
build_number (integer, or a double with whole numbers).
platform is the subdir of the package, such as "linux-64" or
"noarch". Extra columns are kept. An empty environment gives zero
rows with the same columns. create_env() reads these columns to
decide whether an existing environment already has the requested
packages and was built for the requested platform. Default: the
package records, with the columns of micromamba list --json, and the
PyPI packages that pip or uv installed into the environment's python,
as micromamba list lists them (channel pypi, and as platform a
tag such as linux-x86_64). See list_packages().
backend_remove_env(backend, env_name = "condathis-env", verbose = c("output", "silent", "cmd", "spinner", "full")) removes the
environment and its directory. Default: deletes conda-meta/history
first, so the environment leaves every listing at once. Then it moves
the directory into <root>/envs/#trash and deletes it there. When a
program uses one of its files (Windows), the directory cannot be
moved. Then it deletes the files one by one, and moves each file in
use into #trash, where a later call deletes it. A symbolic link is
deleted, never followed. It does not run pre-unlink scripts, and
reports the packages that have one (see Results). Like
create_env(), it deletes only the directory
<backend_get_install_dir()>/envs/<env_name>. A backend whose
backend_get_env_dir() returns another directory needs its own
backend_remove_env(). Without it, remove_env() aborts with
condathis_remove_env_failed, whose parent has the class
condathis_unsafe_env_dir_delete.
backend_available(backend) returns TRUE or FALSE: whether the
backend can create environments on this system now. It must be cheap.
It only decides which backend method = "auto" picks for a new
environment. condathis still lists, finds and uses the existing
environments of an unavailable backend. Default: TRUE.
backend_clean_cache(backend, verbose = c("output", "silent", "cmd", "spinner", "full")) deletes
the package caches and the metadata caches of the backend, and nothing
else. It returns NULL when there was nothing to clean, or a result
list (see Results). clean_cache() calls it for every registered
backend, also after the function of another backend failed, and then
deletes <root>/conda-pkgs itself. Default: NULL.
backend_quiesce(backend, timeout = 30) waits until no work of the
backend runs in the R process any more, at most timeout seconds, and
returns TRUE (invisibly), or FALSE with a warning when the time
ran out. condathis calls it before with_sandbox_dir() and
clean_cache() delete directories. An error from it, or a value other
than TRUE or FALSE, becomes a warning of class
condathis_backend_quiesce_failed, and condathis goes on. A backend
that only starts processes has nothing to wait for. Default: TRUE.
backend_native_platform(backend) returns the platform (subdir) that
the backend solves for when it gets no platform, such as
"osx-arm64", or NA when it cannot tell. Default: NA.
backend_can_solve(backend, packages = NULL, env_file = NULL, channels = "conda-forge", channel_priority = c("strict", "flexible", "disabled"), additional_channels = NULL, platform) returns TRUE when the
request
solves for platform, FALSE when it does not, and NA when it
cannot tell, for example without network access or for a missing
channel. It must not create an environment. condathis asks it when
it chooses the platform of a new environment. A request that does not
solve for the native platform uses an emulated one when it solves
there: "osx-64" on Apple Silicon with Rosetta 2, and "win-64" on
Windows on ARM. An error counts as NA. Default: NA, so condathis
never chooses an emulated platform. condathis never asks it about a
lock (see backend_describe_definition()). It can also take the
optional argument definition = NULL.
backend_describe_definition(backend, definition, platform = NULL)
tells condathis what the backend makes of an env_definition():
whether it reads it, and whether it is a request or a lock.
platform is the platform of create_env(). create_env() calls
it before it locks, moves or creates anything, so it must be cheap:
read the file, but do not download, install or solve anything, and do
not change any environment. It returns a list:
supported: TRUE (the backend reads it), FALSE (it does not) or
NA (it cannot tell). FALSE aborts with class
condathis_create_env_unsupported_definition (also
condathis_backend_unsupported), with reason in the message.
Refuse an option of definition$options that you do not
understand: never ignore it.
format: NA, or the name of the format that the backend detected
or was given, such as "conda-lock-v1".
kind: "request" (the backend solves it, as package specs),
"lock" (it installs exact packages, without a solve) or NA.
platforms: NULL, or the platforms that a lock has packages for.
reason: NA, or one sentence: why supported is FALSE.
records: NULL, or for a lock a data frame with the character
columns name, version, build_string and platform (the
platform the record is for), one row per package that the backend
installs from it.
For a request, condathis goes on as for package specs: it asks
backend_can_solve() about the platform. For a lock, it picks the
platform from platforms and never calls backend_can_solve(),
since a dry run says nothing about a lock. It aborts when
channels, additional_channels or channel_priority were given
with an env_definition() (the deprecated env_file of
create_env() passes them on, as in 0.1.4). Records of noarch
packages install on any platform: leave noarch out of platforms.
When records has rows for the platform and the new environment has
no package, the create fails with condathis_create_env_failed. With
NA as kind, condathis passes the file on and makes no other
check, as for every backend before this function existed. An error
counts as NA.
records also lets condathis compare an existing environment with
a lock: create_env(overwrite = FALSE) keeps the environment when
its packages are exactly the records for the platform, and
validate_env() gives TRUE. Records with NA in name,
version or build_string are not compared. install_packages()
calls this function too, and installs from a request only.
With method = "auto", a new environment from a definition goes to
the first available backend in condathis.backend_priority order
whose supported is not FALSE.
Default: NA, or FALSE when the definition has a format or
options and backend_create_env() has no definition argument.
backend_definition_formats(backend) returns the names of the
formats that the backend reads, as a character vector, such as
c("environment-yaml", "explicit"). It is used only in messages: an
error for a definition with a format names the registered backends
that list it. condathis never decides from it. Default:
character(0).
backend_resolve_run_in_dir(backend, cmd, args = character(0L), env_dir, verbose = "silent", base_env = NULL, timeout = Inf)
describes how to run cmd with args in the activated environment
whose directory (its prefix) is env_dir. This is an environment
given by env_path(), which condathis did not create and which may
belong to no backend, such as one made by conda or mamba elsewhere. It
returns list(command, args, env, dir) with the rules of
backend_resolve_run() (also for base_env and timeout).
condathis treats the value the same way, also when it breaks them.
It must not change, lock or register the environment. condathis
calls it with activation on, after it checked that env_dir exists
and has a conda-meta directory. It calls it only when the backend
object has this function. For a backend without it, run(),
run_bin() and run_pipeline() abort with class
condathis_env_path_unsupported_method (also
condathis_backend_unsupported) when method names that backend.
method = "auto" uses the first backend in the order of the option
condathis.backend_priority that has it (micromamba by default).
Default: aborts with class condathis_backend_unsupported.
Every value is checked: a return value that breaks these rules aborts
with condathis_backend_invalid_return (also
condathis_backend_contract_violation), naming the backend.
backend_create_env(), backend_install(), backend_remove_env() and
backend_clean_cache() may return NULL or a list. condathis copies
the elements status, stdout, stderr, timeout, pid and cmd
when present (exact names) and ignores everything else. Any other value
counts as an empty list. A non-zero status without an error counts as
a failure. cmd is reported as the command line that ran, so give the
exact command line, or leave it out. condathis shows the password and
the token of a URL in it as *****, as micromamba does. Hide them the
same way in what the backend prints and in its errors.
The element link_scripts_skipped of the results of
backend_create_env(), backend_install() and backend_remove_env(),
when present, is a data frame with the character columns package and
script ("pre-link", "post-link" or "pre-unlink"). It holds the
link scripts of packages that the backend did not run. condathis then
warns with class condathis_link_scripts_skipped after the call
succeeded, naming the packages (see condathis-conditions). A backend
that runs every link script, as micromamba does, leaves the element
out. Any other value aborts with condathis_backend_invalid_return.
condathis checks with backend_env_exists() that an environment
exists before it calls backend_install(), backend_remove_env(),
backend_list_packages() and backend_resolve_run(). A missing
environment aborts with class condathis_env_not_found before the
backend is called. So these functions do not get a missing environment
from condathis, except when backend_env_exists() failed. Then
condathis calls them anyway, and they must signal an error for a
missing environment. Give that error the class
condathis_env_not_found. condathis keeps the condathis_* classes
of a backend error when it re-raises it, so one handler catches a
missing environment on both sides. None of them may create an
environment.
Only run(), run_bin(), run_pipeline() and install_packages()
create a missing environment, and only the default "condathis-env":
they call backend_create_env() for an empty environment first.
For a missing environment, backend_env_exists() returns FALSE,
backend_list_envs() leaves the name out, and backend_get_env_dir()
returns the path anyway. None of them signals an error for it.
Signal an error of any class when an operation fails. condathis
re-raises it with your error as the parent, and with these classes:
condathis_<function>_failed, for example
condathis_create_env_failed.
condathis_backend_error.
Every condathis_* class of your error.
Handlers still find your own classes with rlang::cnd_inherits().
When you cannot honor an argument, such as env_file or
channel_priority = "flexible", also give your condition the class
condathis_backend_unsupported.
Do not give your own conditions the class condathis_backend_error:
condathis adds it when it re-raises your error. An error that has it
anyway is re-raised like any other error.
An error from backend_env_exists() means "cannot tell", never
"absent". A call that would change the environment then aborts with
condathis_backend_probe_failed. A query warns with
condathis_backend_query_failed and skips the backend.
See condathis-conditions for every class.
Search only the channels in channels and additional_channels, in that
order, and no default channels. channel_priority has its Conda
meaning. The channel column of backend_list_packages() is the
channel name, as micromamba reports it (for example "conda-forge"), or
the channel URL. condathis compares https://conda.anaconda.org/<name>
equal to <name>, and drops credentials (user:password@,
/t/<token>) and a platform subdirectory. It compares a file://
channel by its absolute path.
condathis starts command with a copy of the session's environment
without the activation of the R session (the binary directories of the
Conda and pixi environments that R runs in are removed from PATH, and
the variables listed in condathis-options are removed or restored),
and with the CONDA_* and MAMBA_* variables listed there cleared. It
then applies env. For commands of
every backend other than "micromamba", CONDA_ENVS_PATH is the
parent directory of the environment directory from
backend_get_env_dir(), so a Conda tool run in the environment creates
named environments next to it. CONDA_PKGS_DIRS and MAMBA_PKGS_DIRS
are <root>/conda-pkgs for them when that parent directory is
<root>/envs, and "" otherwise. A Conda tool run in the environment
keeps its package cache in the backend's root, never in the user's home
directory or in the cache of another backend. clean_cache() empties
it. For an environment given by env_path(), they have the values of
the backend's own environments (those of "condathis-env"), not of the
directory that holds it. The "micromamba" backend sets these
variables to the envs/ and pkgs/ directories of its own root. A
backend whose commands need other values returns them in env.
Put condathis in Imports, so it is loaded before your package, and
register from your package's .onLoad(). Also register from a hook on
the condathis load event. The registry lives in the condathis
namespace, so a registration is lost when condathis is unloaded and
loaded again, as during development with pkgload::load_all(). The hook
registers the backend on every later load of condathis. The hook list
belongs to base R and outlives your package, so .onUnload() must
remove the hook. Otherwise, the next load of condathis registers the
functions of an unloaded namespace.
register_mybackend <- function(...) {
condathis::register_backend("mybackend", new_backend_mybackend())
}
.onLoad <- function(libname, pkgname) {
register_mybackend()
setHook(packageEvent("condathis", "onLoad"), register_mybackend)
invisible(NULL)
}
.onUnload <- function(libpath) {
hook <- packageEvent("condathis", "onLoad")
setHook(
hook,
Filter(function(h) !identical(h, register_mybackend), getHook(hook)),
action = "replace"
)
if (isNamespaceLoaded("condathis")) {
condathis::unregister_backend("mybackend")
}
invisible(NULL)
}
register_mybackend() must be a function at the top level of your
package, so that identical() finds it. A function created inside
.onLoad() is a new object every time. Call condathis functions with
condathis:: instead of importing them in your NAMESPACE. After a
reload of condathis, imported copies would be the functions of the
old namespace.
register_backend() validates the backend, so after a condathis
upgrade that changes the contract, the call in .onLoad() fails and
your package does not load. The error names what to change. R runs the
hook under try(), so a failing hook only prints its error and
condathis still loads.
condathis knows some backend packages by name: rattlerthis provides
the backend "rattler". condathis loads such a package when it is
installed and one of these holds:
method names its backend.
Its backend has environments (a directory in
<backend_root_dir(name)>/envs), so that method = "auto" finds them
without a call to library().
The option condathis.backend_priority names its backend, and
method = "auto" chooses the backend of a new environment.
condathis does not depend on these packages. When such a package is
not installed, or fails to load, a method that names its backend
aborts with class condathis_backend_not_installed or
condathis_backend_load_failed. A change to one of its environments
aborts the same way. The queries skip its environments with a warning of
the same class (see condathis-conditions). The package must register
its backend from its .onLoad(). A package that loads without
registering it counts as failed.
condathis-conditions for the condition classes, and condathis-options for the variables of child processes.
Other backends:
backend_root_dir(),
list_registered_backend_names(),
unregister_backend()
# A minimal backend: the three required functions, which this example # does not implement. It reports that it is unavailable, so # `method = "auto"` never selects it. condathis supplies the other # functions: they look for environments in # `backend_root_dir("mybackend")/envs`. A backend package builds this # object in its own constructor, for example `new_backend_mybackend()` in # *Registering from a backend package* of `?register_backend`. not_implemented <- function(...) { stop("Not implemented by this example backend.", call. = FALSE) } mybackend <- structure( list( backend_create_env = not_implemented, backend_install = not_implemented, backend_resolve_run = not_implemented, backend_available = function(backend) FALSE ), class = c("condathis_backend_mybackend", "condathis_backend") ) condathis::register_backend("mybackend", mybackend) condathis::list_registered_backend_names() condathis::unregister_backend("mybackend") condathis::list_registered_backend_names()# A minimal backend: the three required functions, which this example # does not implement. It reports that it is unavailable, so # `method = "auto"` never selects it. condathis supplies the other # functions: they look for environments in # `backend_root_dir("mybackend")/envs`. A backend package builds this # object in its own constructor, for example `new_backend_mybackend()` in # *Registering from a backend package* of `?register_backend`. not_implemented <- function(...) { stop("Not implemented by this example backend.", call. = FALSE) } mybackend <- structure( list( backend_create_env = not_implemented, backend_install = not_implemented, backend_resolve_run = not_implemented, backend_available = function(backend) FALSE ), class = c("condathis_backend_mybackend", "condathis_backend") ) condathis::register_backend("mybackend", mybackend) condathis::list_registered_backend_names() condathis::unregister_backend("mybackend") condathis::list_registered_backend_names()
Removes an environment managed by condathis.
remove_env( env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full") )remove_env( env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full") )
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
With the micromamba backend, remove_env() deletes the line of the
removed environment from ~/.conda/environments.txt, the registry that
conda and mamba share, when the file has one (see Details in
get_install_dir()). It leaves every other line as it is. On Windows,
it leaves the Start Menu
shortcuts that condathis 0.1.4 and earlier added for packages such as
spyder. Delete them from the Start Menu.
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. stdout, stderr and pid are NA when the
backend reports none, and pid always is with micromamba.
An environment that does not exist aborts with class
condathis_remove_env_env_not_found (also condathis_env_not_found
and the 0.1.4 class condathis_error_env_remove). remove_env()
deletes nothing then, not even a leftover directory of that name.
A backend failure aborts with class condathis_remove_env_failed (also
condathis_backend_error), with the backend's error as the parent.
micromamba runs the pre-unlink scripts of packages before it removes
them. A backend that does not makes remove_env() warn with class
condathis_remove_env_link_scripts_skipped (also
condathis_link_scripts_skipped). The warning names the packages.
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.
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
validate_env()
## Not run: 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" ) condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) condathis::remove_env(env_name = "polyglot-env") }) ## End(Not run)## Not run: 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" ) condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) condathis::remove_env(env_name = "polyglot-env") }) ## End(Not run)
Runs a command line tool with a Conda environment activated. The command
gets the environment variables that the activation sets, including those
of the activate.d scripts of its packages. With activate = FALSE, it
gets a fixed activation instead, without those scripts.
run( cmd, ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL, input = NULL, binary = FALSE, supervise = FALSE, cleanup_tree = FALSE, linux_pdeathsig = FALSE, activate = TRUE, timeout = Inf )run( cmd, ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL, input = NULL, binary = FALSE, supervise = FALSE, cleanup_tree = FALSE, linux_pdeathsig = FALSE, activate = TRUE, timeout = Inf )
cmd |
Character string, the command to run: a single, non-empty
string. Other values abort with class |
... |
Arguments of the command, unnamed: character, numeric or
logical vectors, each element one argument. |
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
error |
Character string that controls what happens when the
command fails. With
A problem with an With Invalid values abort with class |
stdout |
Standard output target: |
stderr |
Standard error target: |
stdin |
Standard input source: |
input |
Character or raw vector written to the standard input of
the command. |
binary |
Logical. Whether to return |
supervise |
Logical. Whether the |
cleanup_tree |
Logical. Whether to kill the process tree of the
command, its child processes included, when the command finishes, times
out, or is interrupted. Defaults to |
linux_pdeathsig |
Logical. On Linux, whether the command gets
|
activate |
Logical. Whether to run |
timeout |
Number of seconds the call may take, the activation of the
environment included (see Details in |
run() activates the environment and starts the command itself. The
micromamba backend records the activation of an environment the first
time a command runs in it. That first command takes longer, and timeout
includes the activation. The backend reuses the activation until the
environment changes (its packages, activate.d scripts or env_vars.d
files). A change in the environment variables of the R session also ends
the reuse.
The command does not get the activation of the R session. When R runs
in an activated Conda or pixi environment, or in several nested ones,
condathis removes their binary directories from PATH and their
variables from the command's environment (see condathis-options,
which also lists what cannot be undone). A program of R's own
environment so never runs in place of one the environment lacks. The
command always runs in exactly one activated environment: CONDA_SHLVL
and MAMBA_SHLVL are 1 and the prompt modifiers are empty. The
command does not get what R's own startup set either: no R_*
variable, and not R's part of LD_LIBRARY_PATH or, on Windows, of
PATH (Rtools).
A bare cmd is looked up on the PATH of the command, after the
activation. On Windows, as in cmd.exe, the working directory of the
command comes first, and a name without an extension is looked up with
the extensions of PATHEXT. A name found nowhere fails with status 127,
as in a shell.
Arguments in ... reach the command exactly as given on every platform.
No shell is involved. Characters such as >, |, &, %, $, * and
quotes have no special meaning. Shell builtins (for example export or
source, or dir and echo on Windows) are not programs and cannot be
run, unless a program of that name is on the PATH of the command (as
echo.exe of Git for Windows). To use shell features, run a shell explicitly, as in
run("bash", "-c", "..."), or on Windows run("cmd", "/c", "dir"). To
connect commands with pipes, use run_pipeline(). One exception applies on
Windows. Windows starts batch files (.bat, .cmd) through cmd.exe,
which parses their arguments again.
When env_name is the default "condathis-env" and that environment
does not exist, run() creates it, empty, with the backend that method
selects. run() never creates any other missing environment. The call
fails, as error describes.
run() does not wait for another R session that changes the
environment, so do not change or remove an environment
(create_env() with overwrite = TRUE, install_packages(),
remove_env()) while commands run in it. Several run() calls can run
in parallel.
The errors of a failed or timed-out command carry the fields status,
stdout, stderr and timeout. A handler does not need to parse the
message, as in
tryCatch(run("false"), condathis_status_error = function(e) e$status).
A condathis_result object, invisibly: a classed list with
status, stdout, stderr, timeout, pid, cmd and env_name,
which prints as a short summary. status is the exit status of the
command. On Linux and macOS, a command that a signal ends has status
128 plus the signal number, as in a shell (143 for SIGTERM).
stdout and stderr are NA when that stream was not captured (a
target other than "|"). pid is the process ID of the command with
stdin = "|", and NA otherwise. cmd is your command line, each part
quoted, with the credentials of URLs masked (see verbose). env_name
is the environment name, or the directory of an env_path().
create_env() to create an environment, env_path() for an
environment created outside condathis, and condathis-conditions
for the condition classes.
Other commands:
parse_output(),
run_bin(),
run_pipeline(),
run_step()
## Not run: 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_env("polyglot", env_name = "polyglot-env", channels = channel) # Run its command, on any platform polyglot_res <- run( "polyglot", env_name = "polyglot-env", verbose = "silent" ) print(parse_output(polyglot_res)[1]) #> [1] "System detected: Linux/Unix" # `pigz` (conda-forge) has builds for Linux, macOS and Windows create_env("conda-forge::pigz", env_name = "pigz-env") # Decompress a FASTQ file shipped with condathis fastq_file <- fs::path_package( "condathis", "extdata", "sample1_L001_R1_001.fastq.gz" ) pigz_res <- run( "pigz", "--decompress", "--stdout", fastq_file, env_name = "pigz-env", verbose = "silent" ) print(parse_output(pigz_res)[1]) #> [1] "@read1/gi|424037187|ref|NR_073460.1| Homo sapiens ribosome ..." }) ## End(Not run)## Not run: 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_env("polyglot", env_name = "polyglot-env", channels = channel) # Run its command, on any platform polyglot_res <- run( "polyglot", env_name = "polyglot-env", verbose = "silent" ) print(parse_output(polyglot_res)[1]) #> [1] "System detected: Linux/Unix" # `pigz` (conda-forge) has builds for Linux, macOS and Windows create_env("conda-forge::pigz", env_name = "pigz-env") # Decompress a FASTQ file shipped with condathis fastq_file <- fs::path_package( "condathis", "extdata", "sample1_L001_R1_001.fastq.gz" ) pigz_res <- run( "pigz", "--decompress", "--stdout", fastq_file, env_name = "pigz-env", verbose = "silent" ) print(parse_output(pigz_res)[1]) #> [1] "@read1/gi|424037187|ref|NR_073460.1| Homo sapiens ribosome ..." }) ## End(Not run)
run_bin() is superseded by run(), which takes the same arguments
and runs the command the same way. run_bin() stays for code written
for earlier versions of condathis. Its errors have their own classes,
condathis_run_bin_*, which also carry the condathis_run_* classes
(see condathis-conditions).
run_bin( cmd, ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL, input = NULL, binary = FALSE, supervise = FALSE, cleanup_tree = FALSE, linux_pdeathsig = FALSE, activate = TRUE, timeout = Inf )run_bin( cmd, ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL, input = NULL, binary = FALSE, supervise = FALSE, cleanup_tree = FALSE, linux_pdeathsig = FALSE, activate = TRUE, timeout = Inf )
cmd |
Character string, the command to run: a single, non-empty
string. Other values abort with class |
... |
Arguments of the command, unnamed, as in |
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
error |
Character string that controls what happens when the
command fails. With
A problem with an With Invalid values abort with class |
stdout |
Standard output target: |
stderr |
Standard error target: |
stdin |
Standard input source: |
input |
Character or raw vector written to the standard input of
the command. |
binary |
Logical. Whether to return |
supervise |
Logical. Whether the |
cleanup_tree |
Logical. Whether to kill the process tree of the
command, its child processes included, when the command finishes, times
out, or is interrupted. Defaults to |
linux_pdeathsig |
Logical. On Linux, whether the command gets
|
activate |
Logical. Whether to run |
timeout |
Number of seconds the call may take, the activation of the
environment included (see Details in |
In condathis 0.1.4, run_bin() ran a program of the environment
without its activation. It now activates the environment, as run()
does. activate = FALSE gives the fixed activation of run().
A condathis_result object, invisibly, as for run().
Other commands:
parse_output(),
run(),
run_pipeline(),
run_step()
## Not run: condathis::with_sandbox_dir({ channel <- system.file( "extdata", "polyglot-channel", package = "condathis" ) condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # The same as condathis::run("polyglot", env_name = "polyglot-env") condathis::run_bin("polyglot", env_name = "polyglot-env") }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ channel <- system.file( "extdata", "polyglot-channel", package = "condathis" ) condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # The same as condathis::run("polyglot", env_name = "polyglot-env") condathis::run_bin("polyglot", env_name = "polyglot-env") }) ## End(Not run)
Runs commands connected with pipes, as cmd1 | cmd2 in a shell. The
standard output of each command is the standard input of the next one.
The data flows between the processes through operating system pipes, not
through R. R gets the standard output of the last command and the
standard error of every command.
Describe each command with run_step(), which takes the same command,
arguments and env_name as run(). Each command can run in a
different Conda environment. Commands that do not set an environment
use the env_name of run_pipeline().
run_pipeline( ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL, input = NULL, binary = FALSE, supervise = TRUE, cleanup_tree = TRUE, linux_pdeathsig = FALSE, activate = TRUE, timeout = Inf )run_pipeline( ..., env_name = "condathis-env", method = "auto", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL, input = NULL, binary = FALSE, supervise = TRUE, cleanup_tree = TRUE, linux_pdeathsig = FALSE, activate = TRUE, timeout = Inf )
... |
Two or more pipeline steps, built with |
env_name |
Character string with the default environment of the
steps that do not set their own, or an environment given by
|
method |
Character string naming the default backend of the steps
that do not set their own
|
verbose |
Character string that controls the console output. One
of
Invalid values abort with class |
error |
Character string that controls what happens when a command
fails. With
The status and timeout errors carry the fields |
stdout |
Standard output target of the last command: |
stderr |
Standard error target for all processes. |
stdin |
Standard input source of the first command: |
input |
Character or raw vector written to the standard input of
the first command, as in |
binary |
Logical. Whether to return raw vectors, not UTF-8 text, for
the standard error of every command and the standard output of the last
one. Defaults to |
supervise |
Logical. Whether the |
cleanup_tree |
Logical. Whether to kill the process tree of each
command, processes that it started in the background included. R kills
the tree when it frees the process object of the command, at a garbage
collection after the pipeline finishes. Defaults to |
linux_pdeathsig |
Logical. On Linux, whether each command gets
|
activate |
Logical. As |
timeout |
Number of seconds the whole pipeline may take, the
activations of the environments included: one deadline for all
commands, not one per command. Defaults to |
A condathis_pipeline object, invisibly, which prints as a
short summary and which parse_output() reads. It is a classed list
with:
status |
Integer. The status of the pipeline: -9 when it timed out, otherwise the status of the first command that failed, or 0. A broken pipe can end a command that is not the last one: that does not count (see Broken pipes). |
statuses |
Integer vector, the exit status of each command. A
command that a signal ends has the status 128 plus the signal number
on Linux and macOS, such as 141 for |
processes |
List of |
timeout |
Logical. Whether the pipeline timed out. |
cmd |
Character string. The command lines of the commands, each
part quoted, joined with |
A command that is not the last one ends as it would in a shell when it
writes again after the next command has exited. On Linux and macOS,
SIGPIPE kills it. Windows has no such signal. There, run_pipeline()
reads the pipe in place of the command that exited. It kills the writer
when more output comes after the pipe was empty for about one second in
total. It also kills the writer when more than 64 KiB comes, which is
what a Linux pipe holds. Output that was already in the pipe does not
count. Either way, the status of the writer is 141, and that is not a
failure. It does not make error = "cancel" abort, and it is not the
status of the result. So seq 1 1000000 | head -n 1 has status 0.
Programs that handle SIGPIPE themselves, such as R and Python, exit
with their own status (R with 1, Python usually with 120), which counts
as a failure. A command that writes nothing more keeps running, on every
platform, and keeps its own status. On Windows, the reader that takes the
place of the exited command is a small Rscript process. When it cannot
start, the writer gets one second to exit on its own, and
run_pipeline() then kills it.
env_path() for an environment created outside condathis,
and condathis-conditions for the condition classes.
Other commands:
parse_output(),
run(),
run_bin(),
run_step()
## Not run: condathis::with_sandbox_dir({ # `pigz` and `ripgrep` (the `rg` binary) come from conda-forge, which # builds both for Linux, macOS and Windows. `rg` is used here instead # of GNU `grep`, which conda-forge has for Windows only as an MSYS2 # package (with the "m2-" prefix). create_env("conda-forge::pigz", env_name = "pigz-env") create_env("conda-forge::ripgrep", env_name = "ripgrep-env") # Pipeline with per-command environments: count the reads of a FASTQ # file shipped with condathis. In this file, the header line of each # read starts with "@read". fastq_file <- fs::path_package( "condathis", "extdata", "sample1_L001_R1_001.fastq.gz" ) res <- run_pipeline( run_step( "pigz", "--decompress", "--stdout", fastq_file, env_name = "pigz-env" ), run_step("rg", "--count", "^@read", env_name = "ripgrep-env"), verbose = "silent" ) print(parse_output(res)) #> [1] "1086" # Steps are values: build a list of them, then splice it in with `!!!` steps <- list( run_step("rg", "--version", env_name = "ripgrep-env"), run_step("rg", "ripgrep", env_name = "ripgrep-env") ) print(parse_output(run_pipeline(!!!steps, verbose = "silent"))) #> [1] "ripgrep 15.2.0 (rev 78115297cd)" }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # `pigz` and `ripgrep` (the `rg` binary) come from conda-forge, which # builds both for Linux, macOS and Windows. `rg` is used here instead # of GNU `grep`, which conda-forge has for Windows only as an MSYS2 # package (with the "m2-" prefix). create_env("conda-forge::pigz", env_name = "pigz-env") create_env("conda-forge::ripgrep", env_name = "ripgrep-env") # Pipeline with per-command environments: count the reads of a FASTQ # file shipped with condathis. In this file, the header line of each # read starts with "@read". fastq_file <- fs::path_package( "condathis", "extdata", "sample1_L001_R1_001.fastq.gz" ) res <- run_pipeline( run_step( "pigz", "--decompress", "--stdout", fastq_file, env_name = "pigz-env" ), run_step("rg", "--count", "^@read", env_name = "ripgrep-env"), verbose = "silent" ) print(parse_output(res)) #> [1] "1086" # Steps are values: build a list of them, then splice it in with `!!!` steps <- list( run_step("rg", "--version", env_name = "ripgrep-env"), run_step("rg", "ripgrep", env_name = "ripgrep-env") ) print(parse_output(run_pipeline(!!!steps, verbose = "silent"))) #> [1] "ripgrep 15.2.0 (rev 78115297cd)" }) ## End(Not run)
Builds one step for run_pipeline(). run_step() takes the same
command, arguments and env_name as run(), but it does not run
anything. It only records the command, so run_pipeline() can start
every step together and connect them with pipes.
run_step(cmd, ..., env_name = NULL, method = NULL, stderr)run_step(cmd, ..., env_name = NULL, method = NULL, stderr)
cmd |
Character string, the command to run: a single, non-empty
string. Its arguments go in |
... |
Arguments of the command, unnamed, as in |
env_name |
Character string with the environment the command runs
in, or an environment given by |
method |
Character string naming the backend for this step, as the
|
stderr |
Standard error target for this step, replacing the
|
run_step() checks arguments when it builds the step, so it reports a
mistake on the line that made it. Each invalid argument aborts with class
condathis_run_step_invalid_<argument>, for example
condathis_run_step_invalid_cmd, and with the shared classes
condathis_invalid_<argument> and condathis_invalid_arg.
An object of class condathis_run_step, for run_pipeline(),
which prints as the command line and its environment.
c() combines steps into a list of steps of
class condathis_run_steps, which c() extends again.
c(step_1, step_2), c(c(step_1, step_2), step_3) and
Reduce(c, steps) all give a list for run_pipeline(!!!steps). c()
with a value that is not a step gives a plain list, as the default
c() does.
Other commands:
parse_output(),
run(),
run_bin(),
run_pipeline()
condathis::run_step( "pigz", "--decompress", "--stdout", "reads.fastq.gz", env_name = "pigz-env" ) condathis::run_step( "rg", "--count", "^@read", env_name = condathis::env_path("/opt/envs/ripgrep") ) # Combine steps with `c()`, then pass them to `run_pipeline()` with `!!!` steps <- c( condathis::run_step("seq", "1", "10"), condathis::run_step("head", "-n", "3") ) stepscondathis::run_step( "pigz", "--decompress", "--stdout", "reads.fastq.gz", env_name = "pigz-env" ) condathis::run_step( "rg", "--count", "^@read", env_name = condathis::env_path("/opt/envs/ripgrep") ) # Combine steps with `c()`, then pass them to `run_pipeline()` with `!!!` steps <- c( condathis::run_step("seq", "1", "10"), condathis::run_step("head", "-n", "3") ) steps
Removes a backend added with register_backend(): the registry entry
and the S3 methods registered for its class. Call it from the
.onUnload() of a backend package (see Registering from a backend
package in register_backend()). Then an unloaded package leaves no
registered backend whose functions belong to a missing namespace.
unregister_backend(name, call = rlang::caller_env())unregister_backend(name, call = rlang::caller_env())
name |
Character string with the backend name to unregister. |
call |
The environment reported as the caller in errors, for calls
from another package's |
Unregistering a name that is not registered does nothing and returns
FALSE, so an unload hook never fails on cleanup that has nothing left
to clean. unregister_backend() refuses the reserved names of
register_backend(), because the built-in "micromamba" backend is
always registered.
Part of the experimental backend extension API. See the
Lifecycle section of register_backend().
Logical, invisibly: TRUE if a backend was unregistered,
FALSE if no backend by that name was registered. A malformed name
aborts with class condathis_backend_invalid_name, and a reserved one
with condathis_backend_reserved_name (also
condathis_backend_invalid_name).
Other backends:
backend_root_dir(),
list_registered_backend_names(),
register_backend()
# A minimal backend: the three required functions, which this example # does not implement. It reports that it is unavailable, so # `method = "auto"` never selects it. condathis supplies the other # functions: they look for environments in # `backend_root_dir("mybackend")/envs`. A backend package builds this # object in its own constructor, for example `new_backend_mybackend()` in # *Registering from a backend package* of `?register_backend`. not_implemented <- function(...) { stop("Not implemented by this example backend.", call. = FALSE) } mybackend <- structure( list( backend_create_env = not_implemented, backend_install = not_implemented, backend_resolve_run = not_implemented, backend_available = function(backend) FALSE ), class = c("condathis_backend_mybackend", "condathis_backend") ) condathis::register_backend("mybackend", mybackend) condathis::list_registered_backend_names() condathis::unregister_backend("mybackend") condathis::list_registered_backend_names()# A minimal backend: the three required functions, which this example # does not implement. It reports that it is unavailable, so # `method = "auto"` never selects it. condathis supplies the other # functions: they look for environments in # `backend_root_dir("mybackend")/envs`. A backend package builds this # object in its own constructor, for example `new_backend_mybackend()` in # *Registering from a backend package* of `?register_backend`. not_implemented <- function(...) { stop("Not implemented by this example backend.", call. = FALSE) } mybackend <- structure( list( backend_create_env = not_implemented, backend_install = not_implemented, backend_resolve_run = not_implemented, backend_available = function(backend) FALSE ), class = c("condathis_backend_mybackend", "condathis_backend") ) condathis::register_backend("mybackend", mybackend) condathis::list_registered_backend_names() condathis::unregister_backend("mybackend") condathis::list_registered_backend_names()
Checks that an environment exists, and that its installed packages
satisfy every package match spec. validate_env() is a query: it never
creates or changes an environment. With the micromamba backend, it
reports an environment that does not exist without starting a process
or installing micromamba.
When no micromamba binary is installed, the micromamba backend reads
the envs directory of its data directory and the package records in
conda-meta/ instead. It never installs micromamba.
validate_env( ..., env_name = "condathis-env", method = "auto", verbose = "silent", channels = NULL, platform = NULL, error = c("cancel", "continue") )validate_env( ..., env_name = "condathis-env", method = "auto", verbose = "silent", channels = NULL, platform = NULL, error = c("cancel", "continue") )
... |
Package match specs (MatchSpec strings), unnamed, as in
Or one lock file, given by These values abort with class
These classes abort too:
Both parse errors also have class |
env_name |
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Invalid values abort with class |
method |
Character string naming the backend. If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
|
verbose |
Character string that controls the console output. One of:
Invalid values abort with class The command line shown, the |
channels |
|
platform |
|
error |
Character string. What happens when the environment does not
exist or does not have the requested packages: |
It uses the same check as create_env(overwrite = FALSE). A spec without
a channel must match a package from channels, or from any channel when
channels is NULL (the default). Given
channels = c(channels, additional_channels) of a create_env() call
(by default "conda-forge"), validate_env() gives the same answer as
that call, with two exceptions. They exist because validate_env() only
reads:
When method names a backend that does not own the environment,
validate_env() warns with class condathis_backend_mismatch_warning
and checks the environment with its owner. create_env() aborts with
class condathis_backend_mismatch.
When a backend cannot tell whether the environment exists,
validate_env() still lists its packages, and reports the listing's
error if it fails. In that case, create_env() aborts with the class
condathis_backend_probe_failed.
TRUE, invisibly, when the environment exists and has every
requested package.
Otherwise, with error = "cancel", it aborts with one of these
classes:
condathis_validate_env_env_not_found (also
condathis_env_not_found)
the environment does not exist.
condathis_validate_env_unsatisfied
a spec is not satisfied or the platform differs. The message lists
each spec that is not satisfied.
With error = "continue", it returns FALSE with two attributes.
reason is one of "env_not_found", "platform_mismatch" and
"unsatisfied". unsatisfied is a character vector of the specs that
are not satisfied (every spec when the environment does not exist).
validate_env() reports a platform mismatch before unsatisfied specs.
For a lock file, unsatisfied lists the packages of the lock that the
environment does not have, as "<name>-<version>-<build>", and a
third attribute, unexpected, lists the packages of the environment
that the lock does not list.
A backend failure aborts with either value of error, with the class
condathis_validate_env_failed (also condathis_backend_error).
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
remove_env()
condathis::with_sandbox_dir({ # A missing environment: FALSE, with the reason res <- condathis::validate_env( "polyglot", env_name = "no-such-env", error = "continue" ) print(res) }) ## Not run: 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" ) condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # TRUE, invisibly. condathis::validate_env("polyglot", env_name = "polyglot-env") # Also TRUE: `polyglot` comes from `channel`, as `create_env()` with # the same channels requires. condathis::validate_env( "polyglot", env_name = "polyglot-env", channels = channel ) # FALSE, with the reason and the specs that are not satisfied. res <- condathis::validate_env( "polyglot>=2", env_name = "polyglot-env", error = "continue" ) print(attr(res, "reason")) #> [1] "unsatisfied" attr(res, "unsatisfied") #> [1] "polyglot>=2" }) ## End(Not run)condathis::with_sandbox_dir({ # A missing environment: FALSE, with the reason res <- condathis::validate_env( "polyglot", env_name = "no-such-env", error = "continue" ) print(res) }) ## Not run: 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" ) condathis::create_env( "polyglot", env_name = "polyglot-env", channels = channel ) # TRUE, invisibly. condathis::validate_env("polyglot", env_name = "polyglot-env") # Also TRUE: `polyglot` comes from `channel`, as `create_env()` with # the same channels requires. condathis::validate_env( "polyglot", env_name = "polyglot-env", channels = channel ) # FALSE, with the reason and the specs that are not satisfied. res <- condathis::validate_env( "polyglot>=2", env_name = "polyglot-env", error = "continue" ) print(attr(res, "reason")) #> [1] "unsatisfied" attr(res, "unsatisfied") #> [1] "polyglot>=2" }) ## End(Not run)
Evaluates code with temporary home, data, cache, configuration and
state directories. It is meant for examples and tests. condathis puts
the environments, packages and micromamba binary that it installs into
the sandbox, with every backend, not into your own directories. No Conda
configuration file of yours is in reach.
with_sandbox_dir(code, .local_envir = base::parent.frame())with_sandbox_dir(code, .local_envir = base::parent.frame())
code |
Expression to evaluate with the temporary directories. |
.local_envir |
Environment |
Processes that condathis starts ignore the session's Conda settings.
Code that starts micromamba or conda itself must pass --no-rc and
--no-env to do the same.
The sandbox lasts exactly as long as the call. Before
with_sandbox_dir() returns, also after an error in code, it does
these steps in this order:
It restores the working directory.
It restores every environment variable, including ones that code
set, changed or removed itself.
It stops the processes that use the sandbox, and their children, if
they are still running. These are the processes that condathis
starts for code. A process counts when its executable or one of its
arguments is a path inside the sandbox. It also counts when it runs
with a condathis environment or package cache inside the sandbox.
Other processes started inside code keep running, for example the
processx supervisor, callr sessions and mirai daemons.
It waits until every backend has finished its work in the R session.
It deletes the sandbox directories, with every environment, package
and micromamba binary installed into them. When it cannot delete them,
with_sandbox_dir() warns with class
condathis_with_sandbox_dir_cleanup_failed. An interrupt during this
cleanup leaves them in the session's temporary directory.
with_sandbox_dir() does not reset options and objects that code
assigns: code runs in .local_envir, as with withr::with_envvar().
It does not change tempdir() or TMPDIR either, so files that code
writes there stay.
The value of code, visible or invisible as in code.
Other setup:
clean_cache(),
get_install_dir(),
get_sys_arch(),
install_micromamba(),
micromamba_bin_path()
condathis::with_sandbox_dir(print(fs::path_home())) condathis::with_sandbox_dir(print(tools::R_user_dir("condathis")))condathis::with_sandbox_dir(print(fs::path_home())) condathis::with_sandbox_dir(print(tools::R_user_dir("condathis")))