Manage packages

Manage dependencies

Add, constrain, move, and remove project dependencies with rpx.

Add and remove packages

Add a package by name:

Terminal
rpx add digest

You can add several packages at once:

Terminal
rpx add jsonlite cli

rpx resolves compatible versions from your configured repositories, adds the dependencies to DESCRIPTION, updates rpx.lock, and installs them into the project library.

You usually don't need to specify a version. For a newly added dependency, rpx selects the latest compatible version and records a range from that version up to, but excluding, the next major release. For example, selecting 1.4.2 produces:

text
Imports:
    examplepkg (>= 1.4.2),
    examplepkg (< 2.0.0)

This allows later releases within the same major version while requiring an explicit change before adopting the next major release. The lockfile records the exact selected version, so synchronizing another machine does not silently upgrade it. For 0.x packages, the upper bound is < 1.0.0.

These bounds assume major versions signal breaking changes. You can adjust them when a package follows a different compatibility policy.

Custom constraints

When you need a specific constraint, use PACKAGE@OPERATORVERSION:

Terminal
rpx add 'digest@>=0.6.37'

Supported operators are <, <=, ==, !=, >=, and >. Quote the expression so your shell does not interpret the operators.

An explicit constraint replaces the automatically generated bounds and any existing constraints for that package.

Remove packages

Terminal
rpx remove digest
rpx remove jsonlite cli

rpx removes the declarations from DESCRIPTION, updates the lockfile, and synchronizes the library. Packages that are no longer needed by the remaining dependencies are removed too.

Dependency types

rpx uses the standard R DESCRIPTION fields:

Field Purpose
Imports Required packages used by your code. The default for rpx add.
Depends Required packages also attached when your package is attached.
LinkingTo Packages providing headers for compilation.
Suggests Optional packages for tests, examples, vignettes, or additional functionality.
Enhances Packages your code optionally extends or integrates with. rpx does not install these.

Because suggested packages are not required to install or load your package, rpx also uses Suggests for development dependencies, preserving the standard DESCRIPTION format.

Terminal
rpx add --dev testthat
rpx add --depends R6
rpx add --linking-to Rcpp

--dev is an alias for --suggests. rpx installs your project's suggestions, but not the suggestions of its dependencies. Adding an existing dependency under another type moves it to that field.

Editing DESCRIPTION

If you edit dependencies in DESCRIPTION directly, resolve them again before synchronizing the library:

Terminal
rpx lock
rpx sync

Installing a package through install.packages() changes the library without recording a dependency in DESCRIPTION or rpx.lock. A later synchronization removes packages outside the locked set. Use rpx add to keep the dependency recorded.

If installation fails after a dependency change, fix the reported problem and run rpx sync again.

Installing only dependencies

For a package project, add and remove also install your project package. Use --no-install-project when you only want its dependencies installed:

Terminal
rpx add --no-install-project digest

If the project package is already installed in the project library, this flag removes it.