Add packages to the Pixi manifest and install them. Pixi only adds them if they can be solved together with the rest of the project's dependencies.
R package names are translated to conda names: "dplyr" becomes r-dplyr
and "Rcpp" becomes r-rcpp (conda names are lowercase). Use a prefix to
say where a package comes from:
"bioc::DESeq2": a Bioconductor package (bioconductor-deseq2from the bioconda channel, which is added to the project if needed). Without the prefix, a package that isn't on conda-forge is looked for on bioconda too, so"DESeq2"works as well. Bioconductor's annotation and data packages, such as org.Hs.eg.db, download their data with an install script, which Pixi only runs in projects that allow it;pixi_add()offers to allow it."conda::gdal": a conda package that isn't an R package, used as is. Names containing-or_, such as"c-compiler", are also used as is."cran::dplyr": same as"dplyr"."pypi::pydytuesday"(experimental): a Python package from PyPI, added withpixi add --pypi, for Python in the project (seeuse_pixi_python())."github::user/repo"(experimental): an R package on GitHub, which Pixi builds from source with its R build backend,pixi-build-r. Add@reffor a branch, tag or commit, as in"github::cran/praise@1.0.0";pixi.lockrecords the exact commit either way. rpix writes it intopixi.toml, turns on Pixi'spixi-buildpreview, and pins the build to the project's R. Its dependencies come from conda-forge. It asks forpixi-build-r0.2.0 or later, which adds the Rust, CMake, pkg-config and R's recommended packages a package needs; a project with packages as of a date before 2026-10-15 can't get it (seepixi_set_date()). rpix also adds whatpixi-build-rdoesn't: Java whenSystemRequirementsnames it, and in a project for Windows, MSYS2'smake,sedandcoreutils, and MinGW's compilers in place ofpixi-build-r's. See https://pixi.prefix.dev/latest/build/backends/pixi-build-r/. This may change, e.g. to usepixi addonce it can set a build backend; see https://github.com/roaldarbol/rpix/issues/96. While Pixi builds, rpix shows a line rather than the build's log, unless the build fails.
In a project with several environments, Pixi doesn't install after adding
or removing, so pixi_add() and pixi_remove() install the environment R
runs in (or else the default one), when the change applies to it.
When it adds R (r-base) to the default feature, it also adds
conda-ecosystem-user-package-isolation, unless it's there, to keep your
personal R library out of the environment's R, as use_pixi() does.
Pixi's output is shown once it has added the packages, or if it fails in a
way rpix can't handle, but not when rpix can, e.g. by looking on bioconda.
To see Pixi's output and build logs as Pixi runs, set
options(rpix.verbose = TRUE).
For more information, see https://pixi.prefix.dev/latest/reference/cli/pixi/add/.
Usage
pixi_add(
packages,
versions = NULL,
channel = NULL,
feature = NULL,
platform = NULL,
type = NULL,
path = NULL,
dry_run = FALSE
)Arguments
- packages
Package names. A version constraint can follow the name, as in
"dplyr>=1.1".- versions
Optional. Version constraints, either one for all packages or one per package (use
NAfor no constraint). A version without an operator, such as"1.1", means1.1.*. For a package from GitHub, it's a branch, tag or commit instead, as with@ref.- channel
Optional. A conda channel to install the packages from. It's added to the project's channels if it isn't there yet.
- feature
Optional. The feature to add the packages to, rather than the default one. See
pixi_add_environment().- platform
Optional. Only add the packages for this platform, such as
"linux-64".- type
Optional. In a package, also add the packages to this field of
DESCRIPTION, asusethis::use_package()does:"Imports","Depends","Suggests","LinkingTo"or"Enhances"for R packages, or"SystemRequirements"for software outside R, given as conda packages ("conda::gdal"). A>=constraint becomes the minimum version there; other constraints only go inpixi.toml. A package from GitHub also goes inRemotes(unless it's CRAN's mirror,cran/).SystemRequirementsgets conda-forge's names, such asgdalorpkg-config, added after what it says already, which stays as it is.DESCRIPTIONchanges once Pixi has added the packages, andfeaturestill decides where they go inpixi.toml.- path
The project. Defaults to the project of the running Pixi environment, or the working directory.
- dry_run
If
TRUE, show the Pixi commands without running them.
Value
The commands (invisibly) if dry_run = TRUE, otherwise the result
of the Pixi call (invisibly).
Examples
# A throwaway Pixi project in R's temporary folder, so the examples leave
# yours alone. With `dry_run = TRUE`, rpix shows the Pixi command it would run.
project <- file.path(tempdir(), "rpix-example")
dir.create(project, showWarnings = FALSE)
writeLines(
c(
"[workspace]",
'name = "rpix-example"',
'channels = ["conda-forge"]',
'platforms = ["linux-64", "osx-arm64", "win-64"]',
"",
"[dependencies]",
'r-base = "4.5.*"',
'conda-ecosystem-user-package-isolation = "*"'
),
file.path(project, "pixi.toml")
)
pixi_add("tibble", path = project, dry_run = TRUE)
#> ℹ Would run: `pixi add r-tibble --manifest-path /tmp/RtmpnAxAUJ/rpix-example/pixi.toml`
pixi_add(
c("dplyr>=1.1", "bioc::DESeq2", "conda::gdal"),
path = project,
dry_run = TRUE
)
#> ℹ Would run: `pixi workspace channel add bioconda --no-install --manifest-path /tmp/RtmpnAxAUJ/rpix-example/pixi.toml`
#> ℹ Would run: `pixi add "r-dplyr>=1.1" bioconda::bioconductor-deseq2 gdal --manifest-path /tmp/RtmpnAxAUJ/rpix-example/pixi.toml`
pixi_add("dplyr", versions = "1.1", path = project, dry_run = TRUE)
#> ℹ Would run: `pixi add r-dplyr=1.1 --manifest-path /tmp/RtmpnAxAUJ/rpix-example/pixi.toml`