Skip to content
Framework

Packages

package_add()

Add a package to the project

Records a package in the project's settings (in settings/packages.yml when the project uses split settings files, otherwise in settings.yml) and installs it if it isn't installed yet. Recording the package is what makes it reproducible: scaffold() and packages_install() install everything listed, and auto-attached packages are loaded by scaffold().

Usage

package_add(package, auto_attach = FALSE, install = TRUE)

Arguments

Name Default Description
package

Package specification: "janitor", a pinned CRAN version ("dplyr@1.1.0"), a GitHub repository ("tidyverse/dplyr@main"), or a Bioconductor package ("bioc::DESeq2").

auto_attach FALSE

Logical. Whether scaffold() loads the package. Default FALSE.

install TRUE

Logical. Install the package now if it isn't installed (or the installed version doesn't match a pin). Default TRUE. If the install fails, the settings are left as they were and package_add() stops.

Value

Invisibly, the package entry that was recorded.

Details

Adding a package that is already listed replaces its entry, so this is also how to pin a version or turn auto-attach on or off.

Afterward, the Installed Packages section of the project's AI context file (ai.canonical_file, else AGENTS.md, else CLAUDE.md) is rewritten from the package settings, so agents see the new package. Only the section marked <!-- @framework:regenerate --> changes; remove the marker to opt out.

Examples

Not run

if (FALSE) {
package_add("janitor")
package_add("forcats", auto_attach = TRUE)
package_add("tidyverse/dplyr@main")
package_add("dplyr@1.1.0")
}

Related reference

Search guides and reference for R, Python, Stata, the CLI, and Framework Cloud.