| Title: | Run Any CLI Tool on a 'Conda' Environment |
|---|---|
| Description: | Simplifies the execution of command line interface (CLI) tools within isolated and reproducible environments. It enables users to effortlessly manage 'Conda' environments, execute command line tools, handle dependencies, and ensure reproducibility in their data analysis workflows. |
| Authors: | Lucio Queiroz [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-6090-1834>), Claudio Zanettini [aut, ctb] (ORCID: <https://orcid.org/0000-0001-5043-8033>) |
| Maintainer: | Lucio Queiroz <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.4 |
| Built: | 2026-06-19 16:39:55 UTC |
| Source: | https://github.com/luciorq/condathis |
Removes cached packages and archives from the condathis Conda root.
Also removes files from the package cache directory returned by
tools::R_user_dir(package = "condathis", which = "cache").
clean_cache(verbose = c("output", "silent", "cmd", "spinner", "full"))clean_cache(verbose = c("output", "silent", "cmd", "spinner", "full"))
verbose |
Character string controlling console output.
Supported values are |
Package files still referenced by existing environments may not be removed.
To maximize cleanup, remove environments first with list_envs() and
remove_env().
A process result list (from processx::run()) with command output,
error output, exit status, and timeout information.
## Not run: condathis::with_sandbox_dir({ clean_cache(verbose = "output") }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ clean_cache(verbose = "output") }) ## End(Not run)
Creates a Conda environment managed by condathis and installs dependencies
from package specs or from an environment file.
create_env( packages = NULL, env_file = NULL, env_name = "condathis-env", channels = c("conda-forge", "bioconda"), method = c("native", "auto"), channel_priority = c("disabled", "strict", "flexible"), additional_channels = NULL, platform = NULL, verbose = c("output", "silent", "cmd", "spinner", "full"), overwrite = FALSE )create_env( packages = NULL, env_file = NULL, env_name = "condathis-env", channels = c("conda-forge", "bioconda"), method = c("native", "auto"), channel_priority = c("disabled", "strict", "flexible"), additional_channels = NULL, platform = NULL, verbose = c("output", "silent", "cmd", "spinner", "full"), overwrite = FALSE )
packages |
Character vector of package MatchSpec strings.
Examples: |
env_file |
Character string with the path to an environment YAML file.
Defaults to |
env_name |
Character string with the target environment name.
Defaults to |
channels |
Character vector with channel names used for dependency
resolution. Defaults to |
method |
Character string with the backend execution strategy.
Supported values are |
channel_priority |
Character string with channel priority mode.
Supported values are |
additional_channels |
Character vector of additional channels appended
to |
platform |
Character string with the platform used for dependency
solving (for example, |
verbose |
Character string controlling console output.
Supported values are |
overwrite |
Logical value that controls whether an existing environment
should always be recreated. Defaults to |
A process result list (from processx::run()) with command output,
error output, exit status, and timeout information.
## Not run: condathis::with_sandbox_dir({ # Create a Conda environment and install the CLI `fastqc` in it. # Explicitly using the channel `bioconda` and version `0.12.1`. condathis::create_env( packages = "bioconda::fastqc==0.12.1", env_name = "fastqc-env", verbose = "output" ) }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # Create a Conda environment and install the CLI `fastqc` in it. # Explicitly using the channel `bioconda` and version `0.12.1`. condathis::create_env( packages = "bioconda::fastqc==0.12.1", env_name = "fastqc-env", verbose = "output" ) }) ## End(Not run)
Checks whether an environment name is present in the environments managed by
condathis.
env_exists(env_name, verbose = "silent")env_exists(env_name, verbose = "silent")
env_name |
Character string with the environment name to check. |
verbose |
Character string controlling console output passed to
|
TRUE when the environment exists and FALSE otherwise.
## Not run: condathis::with_sandbox_dir({ # Create the environment condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) # Check if the environment exists condathis::env_exists("fastqc-env") #> [1] TRUE # Check for a non-existent environment condathis::env_exists("non-existent-env") #> [1] FALSE }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # Create the environment condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) # Check if the environment exists condathis::env_exists("fastqc-env") #> [1] TRUE # Check for a non-existent environment condathis::env_exists("non-existent-env") #> [1] FALSE }) ## End(Not run)
Returns the absolute path where an environment is expected under the
condathis installation root. The path is returned even if the
environment has not been created yet.
get_env_dir(env_name = "condathis-env")get_env_dir(env_name = "condathis-env")
env_name |
Character string with the environment name.
Defaults to |
A character string with the expected environment directory path.
condathis::with_sandbox_dir({ # Get the default environment directory condathis::get_env_dir() #> "/path/to/condathis/envs/condathis-env" # Get the directory for a specific environment condathis::get_env_dir("my-env") #> "/path/to/condathis/envs/my-env" })condathis::with_sandbox_dir({ # Get the default environment directory condathis::get_env_dir() #> "/path/to/condathis/envs/condathis-env" # Get the directory for a specific environment condathis::get_env_dir("my-env") #> "/path/to/condathis/envs/my-env" })
condathis data directoryReturns the data directory used by condathis, creating it when needed.
The base path follows the platform-specific user data directory rules used
by tools::R_user_dir().
get_install_dir()get_install_dir()
On macOS, condathis uses a path without spaces when possible because
micromamba run can fail on paths that contain spaces.
A character string with the normalized, real path to the
condathis data directory.
condathis::with_sandbox_dir({ print(condathis::get_install_dir()) #> /home/username/.local/share/condathis })condathis::with_sandbox_dir({ print(condathis::get_install_dir()) #> /home/username/.local/share/condathis })
Returns the current operating system and CPU architecture as a single
string in the format "<OS>-<Architecture>".
get_sys_arch()get_sys_arch()
A character string such as "Darwin-x86_64" or
"Linux-aarch64".
# Retrieve the system architecture condathis::get_sys_arch() #> [1] "Darwin-x86_64"# Retrieve the system architecture condathis::get_sys_arch() #> [1] "Darwin-x86_64"
Downloads and installs the micromamba executable used by condathis.
install_micromamba( micromamba_version = "2.8.1-0", timeout_limit = 3600, download_method = "auto", force = FALSE, verbose = c("output", "silent", "cmd", "spinner", "full") )install_micromamba( micromamba_version = "2.8.1-0", timeout_limit = 3600, download_method = "auto", force = FALSE, verbose = c("output", "silent", "cmd", "spinner", "full") )
micromamba_version |
Character string with the micromamba version.
Defaults to |
timeout_limit |
Numeric download timeout in seconds.
Defaults to |
download_method |
Character string passed as the download method when
|
force |
Logical value that controls forced reinstallation.
Defaults to |
verbose |
Character string controlling console output.
Supported values are |
Download mirrors are tried in order until one succeeds.
When system tar and bzip2 are available, a compressed archive may be
used first. Otherwise, or when extraction fails, a standalone binary is
downloaded.
The installed micromamba binary path, invisibly.
## Not run: condathis::with_sandbox_dir({ # Install the default version of Micromamba condathis::install_micromamba() # Install a specific version of Micromamba condathis::install_micromamba(micromamba_version = "2.0.2-2") # Force reinstallation of Micromamba 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 of Micromamba condathis::install_micromamba(micromamba_version = "2.0.2-2") # Force reinstallation of Micromamba condathis::install_micromamba(force = TRUE) }) ## End(Not run)
Installs packages into an existing condathis environment.
If the target environment does not exist, it is created first.
install_packages( packages, env_name = "condathis-env", channels = c("conda-forge", "bioconda"), channel_priority = c("disabled", "strict", "flexible"), additional_channels = NULL, verbose = c("output", "silent", "cmd", "spinner", "full") )install_packages( packages, env_name = "condathis-env", channels = c("conda-forge", "bioconda"), channel_priority = c("disabled", "strict", "flexible"), additional_channels = NULL, verbose = c("output", "silent", "cmd", "spinner", "full") )
packages |
Character vector of package MatchSpec strings to install. |
env_name |
Character string with the target environment name.
Defaults to |
channels |
Character vector with channel names used for dependency
resolution. Defaults to |
channel_priority |
Character string with channel priority mode.
Supported values are |
additional_channels |
Character vector of additional channels appended
to |
verbose |
Character string controlling console output.
Supported values are |
A process result list (from processx::run()) with command output,
error output, exit status, and timeout information.
## Not run: condathis::with_sandbox_dir({ condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) # Install the package `python` in the `fastqc-env` environment. # NOTE: It is not recommended to install multiple packages in the same # environment, as it defeats the purpose of isolation provided by # separate environments. condathis::install_packages(packages = "python", env_name = "fastqc-env") }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) # Install the package `python` in the `fastqc-env` environment. # NOTE: It is not recommended to install multiple packages in the same # environment, as it defeats the purpose of isolation provided by # separate environments. condathis::install_packages(packages = "python", env_name = "fastqc-env") }) ## End(Not run)
Returns environment names located under the condathis installation root.
Environments not managed by condathis are excluded.
list_envs(verbose = "silent")list_envs(verbose = "silent")
verbose |
Character string controlling console output.
Defaults to |
A character vector of environment names. If the command fails, returns the process exit status as a numeric value.
## Not run: condathis::with_sandbox_dir({ # Create environments condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) condathis::create_env( packages = "python", env_name = "python-env" ) # List environments condathis::list_envs() #> [1] "fastqc-env" "python-env" }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # Create environments condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) condathis::create_env( packages = "python", env_name = "python-env" ) # List environments condathis::list_envs() #> [1] "fastqc-env" "python-env" }) ## End(Not run)
Returns package metadata for a Conda environment as a tibble.
list_packages( env_name = "condathis-env", verbose = c("output", "silent", "cmd", "spinner", "full") )list_packages( env_name = "condathis-env", verbose = c("output", "silent", "cmd", "spinner", "full") )
env_name |
Character string with the target environment name.
Defaults to |
verbose |
Character string controlling console output.
Supported values are |
A data frame (tibble) with installed packages and the columns:
base_url: The base URL of the package source.
build_number: The build number of the package.
build_string: The build string describing the package build details.
channel: The channel from which the package was installed.
dist_name: The distribution name of the package.
name: The name of the package.
platform: The platform for which the package is built.
version: The version of the package.
## Not run: condathis::with_sandbox_dir({ # Creates a Conda environment with the CLI `fastqc` condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) # Lists the packages in env `fastqc-env` dat <- condathis::list_packages("fastqc-env") dim(dat) #> [1] 34 8 }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # Creates a Conda environment with the CLI `fastqc` condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) # Lists the packages in env `fastqc-env` dat <- condathis::list_packages("fastqc-env") dim(dat) #> [1] 34 8 }) ## End(Not run)
micromamba binary pathReturns the expected path to the micromamba executable managed by
condathis for the current operating system.
micromamba_bin_path()micromamba_bin_path()
A character string with the full executable path.
On Windows this points to micromamba.exe under Library/bin.
On other platforms this points to micromamba under bin.
condathis::with_sandbox_dir({ # Retrieve the path used by condathis for micromamba micromamba_path <- condathis::micromamba_bin_path() print(micromamba_path) })condathis::with_sandbox_dir({ # Retrieve the path used by condathis for micromamba micromamba_path <- condathis::micromamba_bin_path() print(micromamba_path) })
Parses output from a run() result into trimmed text lines.
parse_output(res, stream = c("stdout", "stderr", "both", "plain"))parse_output(res, stream = c("stdout", "stderr", "both", "plain"))
res |
Either a process result list (with |
stream |
Character string selecting the output source.
Supported values are |
A character vector with one trimmed line per element.
# Example result object from condathis::run() 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")# Example result object from condathis::run() 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")
Removes an environment managed by condathis.
remove_env( env_name = "condathis-env", verbose = c("silent", "cmd", "output", "spinner", "full") )remove_env( env_name = "condathis-env", verbose = c("silent", "cmd", "output", "spinner", "full") )
env_name |
Character string with the environment name to remove.
Defaults to |
verbose |
Character string controlling console output.
Supported values are |
A process result list (from processx::run()) with command output,
error output, exit status, and timeout information.
## Not run: condathis::with_sandbox_dir({ condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) condathis::remove_env(env_name = "fastqc-env") }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ condathis::create_env( packages = "bioconda::fastqc", env_name = "fastqc-env" ) condathis::remove_env(env_name = "fastqc-env") }) ## End(Not run)
Executes a command in a Conda environment managed by condathis.
The command is run through micromamba run using the internal Conda root.
run( cmd, ..., env_name = "condathis-env", method = c("native", "auto"), verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL )run( cmd, ..., env_name = "condathis-env", method = c("native", "auto"), verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL )
cmd |
Character string with the command to execute. |
... |
Additional unnamed command arguments passed to |
env_name |
Character string with the target environment name.
Defaults to |
method |
Character string with the backend execution strategy.
Supported values are |
verbose |
Character string controlling console output.
Supported values are |
error |
Character string that controls error behavior.
Supported values are |
stdout |
Standard output target.
Defaults to |
stderr |
Standard error target.
Defaults to |
stdin |
Standard input source.
Defaults to |
This function is the main execution entry point in condathis.
Use it to run CLI tools with reproducible dependencies isolated in Conda
environments.
A process result list (from processx::run()) with command output,
error output, exit status, and timeout information.
install_micromamba, create_env
## Not run: condathis::with_sandbox_dir({ ## Create env create_env("bioconda::samtools", env_name = "samtools-env") ## Run a command in a specific Conda environment samtools_res <- run( "samtools", "view", fs::path_package("condathis", "extdata", "example.bam"), env_name = "samtools-env", verbose = "silent" ) parse_output(samtools_res)[1] #> [1] "SOLEXA-1GA-1_6_FC20ET7:6:92:473:531\t0\tchr1\t10156..." }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ ## Create env create_env("bioconda::samtools", env_name = "samtools-env") ## Run a command in a specific Conda environment samtools_res <- run( "samtools", "view", fs::path_package("condathis", "extdata", "example.bam"), env_name = "samtools-env", verbose = "silent" ) parse_output(samtools_res)[1] #> [1] "SOLEXA-1GA-1_6_FC20ET7:6:92:473:531\t0\tchr1\t10156..." }) ## End(Not run)
Executes a binary using files from a target Conda environment, but without
running environment activation scripts.
This is a lower-level execution mode than run().
run_bin( cmd, ..., env_name = "condathis-env", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL )run_bin( cmd, ..., env_name = "condathis-env", verbose = c("output", "silent", "cmd", "spinner", "full"), error = c("cancel", "continue"), stdout = "|", stderr = "|", stdin = NULL )
cmd |
Character string with the command to execute. |
... |
Additional unnamed command arguments passed to |
env_name |
Character string with the target environment name.
Defaults to |
verbose |
Character string controlling console output.
Supported values are |
error |
Character string that controls error behavior.
Supported values are |
stdout |
Standard output target.
Defaults to |
stderr |
Standard error target.
Defaults to |
stdin |
Standard input source.
Defaults to |
A process result list (from processx::run()) with command output,
error output, exit status, and timeout information.
## Not run: condathis::with_sandbox_dir({ # Example assumes that 'my-env' exists and contains 'python' # Run 'python' with a script in 'my-env' environment condathis::run_bin( "python", "-c", "import sys; print(sys.version)", env_name = "my-env" ) # Run 'ls' command with additional arguments condathis::run_bin("ls", "-la", env_name = "my-env") }) ## End(Not run)## Not run: condathis::with_sandbox_dir({ # Example assumes that 'my-env' exists and contains 'python' # Run 'python' with a script in 'my-env' environment condathis::run_bin( "python", "-c", "import sys; print(sys.version)", env_name = "my-env" ) # Run 'ls' command with additional arguments condathis::run_bin("ls", "-la", env_name = "my-env") }) ## End(Not run)
Evaluates code with temporary home, data, and cache directories. This is mainly intended for examples and tests so no user files are written.
with_sandbox_dir(code, .local_envir = base::parent.frame())with_sandbox_dir(code, .local_envir = base::parent.frame())
code |
Expression to evaluate in the sandboxed environment. |
.local_envir |
Environment used for local scoping and evaluation.
Defaults to |
NULL, invisibly.
## Not run: condathis::with_sandbox_dir(print(fs::path_home())) condathis::with_sandbox_dir(print(tools::R_user_dir("condathis"))) ## End(Not run)## Not run: condathis::with_sandbox_dir(print(fs::path_home())) condathis::with_sandbox_dir(print(tools::R_user_dir("condathis"))) ## End(Not run)