Curated CRAN Sources

EnhancedAdvanced

This section provides an overview of what curated-cran sources are, why they are useful, and how to use them. If you are already familiar with curated-cran sources, then reference the Initial Configuration section on creating your first curated subset of CRAN.

To serve all of CRAN instead of a subset, see Serving CRAN Packages. To serve R packages you build yourself, see Distributing Local R Packages.

Overview

Curated CRAN sources are based on a current mirror of CRAN. It can be useful to only include certain CRAN packages and versions within a source. This is especially helpful in secure, regulated environments, where only verified sets of packages are allowed.

Creating a Curated CRAN Source

Terminal
$ rspm create source --name=subset --type=curated-cran
Source 'subset':
 Type:  Curated CRAN - 2024-04-17

EnhancedAdvanced To let users request packages for this source, add --enable-package-requests to the command.

Creating a Curated CRAN Source With No Archived Packages

Curated CRAN sources can be created without archived packages. This is useful when you want to ensure that only the latest versions of packages are available in the source. To create a curated CRAN source without archived packages, use the --no-archived flag:

Terminal
$ rspm create source --name=subset --type=curated-cran --no-archived
Source 'subset':
 Type:  Curated CRAN - 2024-04-17

Curated CRAN sources don’t need to be pinned to a specific snapshot date at the time of creation; any date can be picked when adding packages with rspm update (described below). Once the source has been created, be sure to subscribe a repository to the source to make the packages available to users:

Terminal
# Create a repository:
$ rspm create repo --name=cran --type=r --description='Access Curated CRAN packages'
Repository: cran - Access Curated CRAN packages - R

# Subscribe a repository to the curated-cran source:
$ rspm subscribe --repo=cran --source=subset
Repository: cran
Sources:
--subset (Curated CRAN - 2024-04-17)

Including Packages in a Curated CRAN Source

Packages are included in a curated-cran source by uploading a requirements.txt definition with rspm update. This section explains how a requirements file is defined and also discusses how to use a requirements file to include packages in a curated-cran source.

Requirements Files

The requirements.txt format that Package Manager looks at is defined as:

Curated CRAN Requirements Format
[package name] [optionally: version constraints] [[optionally: extras]]

The extras block allows you to specify which types of related packages should be included along with the package itself.

The extras block is additive to the --include flag that the source was created with. See the section on source-level included packages to learn more.

The following values are valid for the extras block:

  • depends
  • imports
  • linking-to
  • suggests
  • all
NoteSuggested dependency inclusions

Suggested dependencies, when included, are included only at a single level, not recursively; all other types are included recursively.

As an example, a requirements.txt file could look like:

requirements.txt
A3 >= 0.9.2 [all]
ggplot2 == 3.4.4
plumber [suggests]

-r requirements2.txt

This fetches and installs:

  • A3 with versions greater than or equal to 0.9.2 along with all related packages
  • Only ggplot2 version 3.4.4
  • All available versions of plumber along with suggested packages.
  • All packages from requirements2.txt.

Filtering by version is not supported for:

  • Curated CRAN sources created prior to Package Manager version 2024.04
  • Sources created using the --strict flag

By default, the depends, imports, and linking-to dependencies for each package are included. The default types of related packages to include can be configured per source.

See the section on source-level included packages to learn more.

As shown in the example above, a package doesn’t need to have any version constraints defined. It can also have as many version constraints as needed. The versions made available to Package Manager depend on what is available at the snapshot date specified when updating the source.

All version parsing and matching criteria is based on PEP-440. Refer to the PEP-440 documentation for information on version formatting and constraints. For more information on the Requirements File Format, refer to pip’s documentation.

Noterequirements.txt limitations

Not everything defined in the Requirements File Format specification is supported in Package Manager.

The curated-cran source only parses package names, version ranges, and recursive file references. Any other definitions (e.g., option flags, environment markers) within an uploaded requirements.txt file is ignored. The exception is the Bioconductor lines described in Adding the CRAN Dependencies of Bioconductor Packages.

The requirements.txt file also supports declaring multiple references of the same package with different version constraints:

requirements.txt
tidyr == 1.3.0
...
tidyr == 1.3.1

This will be treated as an OR operator, leading the curated-cran source to evaluate the defined version constraints as “tidyr == 1.3.0 or tidyr == 1.3.13”.

In this example, Package Manager pulls in version 1.3.0 and version 1.3.1.

NoteExcluding a package using multiple references

Use caution when referencing a package multiple times when using a != constraint. As an example:

requirements.txt
tidyr >= 1.1.0, < 1.3.0
...
tidyr != 1.2.1

This still includes version 1.2.1 because it is being evaluated as “tidyr >= 1.1.0, < 1.3.0 or tidyr != 1.2.1”

To guarantee that version 1.2.1 is excluded, include all version constraints on a single line so Package Manager evaluates all constraints together:

tidyr >= 1.1.0, < 1.3.0, != 1.2.1

Filtering out package versions can break the R package graph, so it must be done with care.

Adding the CRAN Dependencies of Bioconductor Packages

Bioconductor packages often depend on CRAN packages. To make those CRAN dependencies available, add a --for-bioconductor <version> <path> line to the requirements file. <version> is a Bioconductor version, such as 3.20. <path> is a requirements file that lists Bioconductor packages, such as the one you give a curated-bioconductor source. The path resolves against the directory of the requirements file, and you can repeat the line for more versions.

requirements.txt
dplyr
--for-bioconductor 3.20 bioc-requirements.txt

Package Manager adds the CRAN packages that the Bioconductor packages in that file need, through Depends, Imports, and LinkingTo. It never adds the Bioconductor packages themselves to the source or serves them. Package Manager reads the Bioconductor packages at the newest Bioconductor snapshot of that version on or before the CRAN snapshot you update to.

When you run rspm update --file-in, rspm replaces each --for-bioconductor line with one marked line per Bioconductor package. You can also write a marked line yourself in the file you pass to rspm update. pkg; bioc_version == "3.20" names a Bioconductor package that Package Manager keeps only for its CRAN dependencies. The update fails if the Bioconductor version has no snapshot. rspm add accepts --for-bioconductor lines in --file-in, but rejects a marked line that you write yourself.

To use a different Bioconductor snapshot, pass --bioc-snapshot VERSION=DATE to rspm update or rspm add, for example --bioc-snapshot 3.20=2025-11-12. Package Manager uses the newest snapshot of that Bioconductor version on or before DATE, which might be later than the CRAN snapshot. Repeat the flag for more versions. The flag applies to that run only.

When you run rspm update on a curated-bioconductor source, Package Manager lists the CRAN packages the set needs and prints the --for-bioconductor line to add to your CRAN requirements file. If the set needs no CRAN packages, nothing is printed.

The line is valid only in a CRAN requirements file. A curated-bioconductor update rejects it. For the opposite direction, see Adding the Bioconductor Dependencies of CRAN Packages. For the offline downloader, see Adding the CRAN dependencies of Bioconductor packages.

Updating a Curated CRAN Source

Run rspm update with a requirements file and CRAN snapshot date to preview changes before committing them.

This example updates the subset source, which already contains the cli package at version 3.6.2. Neither output lists the cli package because its version does not change. Save these requirements in requirements.txt:

requirements.txt
tibble
rlang
Terminal
rspm update --source=subset --file-in=requirements.txt --snapshot=2024-01-04

To preview changes at the most recent snapshot available, omit the --snapshot flag.

Package Manager previews the changes:

Output
Packages from 'requirements.txt' to update source 'subset' at CRAN snapshot date '2024-01-04':

Name      Version Action Needs Compilation Dependency
fansi     1.0.6   add    yes               true
glue      1.6.2   add    yes               true
lifecycle 1.0.4   add    no                true
magrittr  2.0.3   add    yes               true
pillar    1.9.0   add    no                true
pkgconfig 2.0.3   add    no                true
rlang     1.1.2   add    yes               false
tibble    3.2.1   add    yes               false
utf8      1.2.4   add    yes               true
vctrs     0.6.5   add    yes               true

If the output above looks correct, execute this command again with the --commit and --snapshot=2024-01-04 flags to update the source with the new set of packages.

Both outputs list added, updated, and removed packages. They omit unchanged packages.

  • Needs Compilation indicates whether an added or updated package requires compilation when installed from source: yes or no.
  • Dependency is true when Package Manager adds or updates the package implicitly as a dependency.
  • Dependency is false when your requirements file explicitly lists an added or updated package, even if another listed package depends on it.

To commit the changes, repeat the command, adding the --commit flag:

Terminal
rspm update --source=subset --file-in=requirements.txt --snapshot=2024-01-04 --commit

Package Manager prints the committed changes:

Output
Successfully updated source 'subset' at CRAN snapshot date '2024-01-04' with the following packages from 'requirements.txt':

Name      Version Action Needs Compilation Dependency
fansi     1.0.6   add    yes               true
glue      1.6.2   add    yes               true
lifecycle 1.0.4   add    no                true
magrittr  2.0.3   add    yes               true
pillar    1.9.0   add    no                true
pkgconfig 2.0.3   add    no                true
rlang     1.1.2   add    yes               false
tibble    3.2.1   add    yes               false
utf8      1.2.4   add    yes               true
vctrs     0.6.5   add    yes               true
Warningrspm update overwrite behavior

Running rspm update on a Curated CRAN source overwrites the source with only the packages defined in your requirements.txt file. However, previous snapshots of the source are still available with a pinned repo URL.

To update the source to a different snapshot date, use the update command again:

Terminal
# Update packages in a curated-cran source:
rspm update --source=subset --file-in=/path/to/requirements.txt --snapshot=2024-04-18 --commit

Curated CRAN sources can be pinned to any date for which Posit has a CRAN snapshot (typically, once per weekday). Curated CRAN sources also support using any date, regardless of the previously used snapshot dates. If the source was initially set to 2021-02-03, it can then be set to a later date with --snapshot=2022-06-01. If later you would like to pin it back to the original date used, that can be done by running rspm update again with --snapshot=2021-02-03.

TipCurated CRAN snapshots

This allows you to set the Curated CRAN source to any date where a CRAN snapshot has been taken on our servers. To pin to a version of a package that doesn’t exist on CRAN anymore, pin to a date when the version of the package existed.

The snapshot date for non-strict sources can be moved both forwards and backwards in time.

Source-Level Included Packages

A Curated CRAN source will automatically include the related depends, imports, and linking-to packages for each requested package.

You can change the types of related packages that are included when creating a source. This can be done by passing in the --include flag. For example:

Terminal
# Equivalent to the default setting
rspm create source --name=subset --type=curated-cran --include=depends,imports,linking-to

# Include the defaults plus `suggests`
rspm create source --name=subset --type=curated-cran --include=depends,imports,linking-to,suggests

# Don't include any related packages
rspm create source --name=subset --type=curated-cran --include=none

# Include all related packages:
rspm create source --name=subset --type=curated-cran --include=all
WarningEditing --include

The value of the --include cannot be changed after source creation.

The following options are valid options for the --include flag:

  • depends
  • imports
  • linking-to
  • suggests
  • none
  • all
NoteSuggested dependency inclusions

Suggested dependencies, when included, are included only at a single level, not recursively; all other types are included recursively.

Included related packages can also be configured per-package by adding an extras block to your packages in the requirements.txt file. For example:

The extras block is additive to the --include flag that the source was created with.

requirements.txt
A3 >= 0.9.2 [all]
ggplot2 == 3.4.4
plumber [depends, imports, linking-to, suggests]
  • A3 with versions greater than or equal to 0.9.2 plus all related packages
  • ggplot2 version 3.4.4 using the default inclusions
  • All versions of plumber plus depends, imports, linking-to, and suggests packages

Strict Curated CRAN

Older Curated CRAN sources (those created before Package Manager version 2024.04) use a less permissive package version snapshot behavior. You can still create Curated CRAN sources using the previous behavior by using the --strict option when creating the source:

Terminal
$ rspm create source --name=subset --type=curated-cran --strict
Source 'subset':
Type:  Curated CRAN - 2024-04-18 - Strict
WarningEditing --strict

The value of the --strict cannot be changed after source creation.

A strict source does not limit an approved package request to the approved versions.

Strict vs Default Sources

When a source uses the new default archive policy, updates to the source incorporate all versions of the affected package to match the associated CRAN snapshot. The package versions associated with a curated snapshot will match the versions available for the associated CRAN snapshot, including current and archived packages.

When a source uses the --strict archive policy, any updates to the source incorporates only the current versions of the affected packages. Any previous package versions associated with the source at the previous transaction are recorded as archived packages.

Strict sources are useful for those who need more control over available versions without the ability to add version constraints. Non-strict sources are significantly more flexible.

rspm add vs rspm update

The rspm add command is still supported to add packages to Curated CRAN sources, however it is recommended that rspm update is used instead. rspm add may be deprecated in a future release of Package Manager.

rspm add can be used to add individual packages to a Curated CRAN source:

Terminal
# Specify the top-level packages you want to add:
rspm add --packages=ggplot2,shiny --source=subset

Package Manager previews the package changes. Use the --csv-out flag to save the preview to a CSV file. Package Manager includes required dependencies for the named packages. Use the --include-suggests flag to include suggested packages.

The output uses the same columns as Curated CRAN update output.

To commit the changes, repeat the command, adding the --commit flag.

Terminal
# Commit the top-level packages you want to add:
rspm add --packages=ggplot2,shiny --source=subset --snapshot=2020-07-06 --commit

rspm add also supports adding a large number of packages that are specified in a file. To do this, create a file containing one package name per line. For example, /tmp/packages.csv:

/tmp/packages.csv
plumber
shiny
ISLR

Then use the add command, this time using the --file-in flag:

Terminal
rspm add --file-in='/tmp/packages.csv' --source=subset
Back to top