Skip to content

rv add examples

The rv add command supports a wide range of options for adding packages to your project. This page demonstrates various ways to use rv add with different package sources and configuration options.

Add a package using the default behavior - creates a simple string dependency entry:

Terminal window
rv add dplyr

Result in rproject.toml:

dependencies = ["dplyr"]

Add a package from a specific repository using the --repository flag:

Terminal window
rv add polars --repository RMV25Q3

Result in rproject.toml:

dependencies = [
{ name = "polars", repository = "RMV25Q3" }
]

This is useful when you need to install a package from a non-default repository, such as R-multiverse snapshots.

Force installation from source for all repositories:

Terminal window
rv add dplyr --force-source

Result in rproject.toml:

dependencies = [
{ name = "dplyr", force_source = true }
]

Combine repository targeting, force source, and install suggestions:

Terminal window
rv add dplyr --repository cran --force-source --install-suggestions

Result in rproject.toml:

dependencies = [
{ name = "dplyr", repository = "cran", force_source = true, install_suggestions = true }
]

Install from a git repository with a specific tag:

Terminal window
rv add my-pkg --git https://github.com/user/repo --tag v1.0.0

Result in rproject.toml:

dependencies = [
{ name = "my-pkg", git = "https://github.com/user/repo", tag = "v1.0.0" }
]

Install from a git repository with branch, subdirectory, and additional options:

Terminal window
rv add my-pkg --git https://github.com/user/repo --branch main --directory subpkg --install-suggestions --dependencies-only

Result in rproject.toml:

dependencies = [
{ name = "my-pkg", git = "https://github.com/user/repo", branch = "main",
directory = "subpkg", install_suggestions = true, dependencies_only = true }
]

Install a package from a local path:

Terminal window
rv add my-pkg --path ../my-package

Result in rproject.toml:

dependencies = [
{ name = "my-pkg", path = "../my-package" }
]

Install from a direct URL to a package archive:

Terminal window
rv add dplyr --url https://cran.r-project.org/src/contrib/Archive/dplyr/dplyr_1.1.3.tar.gz

Result in rproject.toml:

dependencies = [
{ name = "dplyr", url = "https://cran.r-project.org/src/contrib/Archive/dplyr/dplyr_1.1.3.tar.gz" }
]

Install only the dependencies of a package without installing the package itself. This is particularly useful when actively developing a package:

Terminal window
rv add my-dev-pkg --path . --dependencies-only

Result in rproject.toml:

dependencies = [
{ name = "my-dev-pkg", path = ".", dependencies_only = true }
]

This installs all dependencies of my-dev-pkg but not my-dev-pkg itself, which is ideal for development workflows.