Integrating Posit Connect with Posit Package Manager

Posit Package Manager is a repository management server product that makes it easy to organize and centralize R packages at your organization. Package Manager can help if your organization needs offline CRAN access, package access restrictions, internal package sharing, or other special package management needs. To learn more, visit the Package Manager Product Page and speak to your dedicated Posit Customer Success contact.

Overriding CRAN with Package Manager

You might want to redefine CRAN or another R package repository to point to your organization’s Package Manager repository, or at some other private R package repository that you have set up.

When a user deploys R content, the content comes with a packrat.lock file or a manifest.json file used to generate the packrat.lock file. This file contains the versions and cryptographic hashes of all the package dependencies for the content, as well as the URLs of the package repositories in the deploying user’s environment. CRAN is one such repository, and it is the most commonly used repository for R programming.

You should first obtain the repository link from Package Manager:

  1. Open Package Manager

  2. Select your repository in the Repos list on the left side of the screen

  3. Select Setup in the navigation bar at the top of the screen

  4. Under Repository URL, select whether you want the latest checkpoint or select a date to freeze the packages to a particular date.

    Important

    Freezing your repository to a date can lead to users attempting to deploy content containing package versions that did not exist at that date. If that happens, their content will fail to build because it cannot find necessary packages.

  5. If present on your version of Package Manager, select whether you want Source or Binary packages.

    Important

    If you choose binary packages, you must select the distribution that matches the distribution of Linux you are using on Connect.

  6. Under Use this URL… link, copy the URL.

  7. In the /etc/rstudio-connect/rstudio-connect.gcfg configuration file, add the following setting, replacing <the URL you copied> with the URL that you copied in the previous step:

    [RPackageRepository "CRAN"]
    URL = <the URL you copied>
Note

The location of the binary and the command line options you need to pass can vary depending on where your installation is located on the filesystem.

For additional information, please see the r-package-repositories section and the RPackageRepository section of the Appendix.

Posit Package Manager URL rewriting

Posit Package Manager can serve R packages as source or precompiled binaries. Precompiled binaries install much faster, but are only compatible with the Linux distribution for which they were compiled. For more detail, see Posit Package Manager documentation on Binary Packages and Using Linux Binary Packages.

Note

Package Manager URL rewriting only applies to Posit Package Manager URLs. Other R package repositories (e.g. vanilla CRAN mirrors, Bioconductor, Artifactory, or filesystem repositories) are not affected.

The type of package served by Posit Package Manager is determined by the URL. For instance, https://packagemanager.posit.co/cran/latest serves source packages, while https://packagemanager.posit.co/cran/__linux__/jammy/latest serves binary packages for Ubuntu 22.04.

Use the setting R.PositPackageManagerURLRewriting to control how Connect downloads packages from a Posit Package Manager instance. This setting affects both repositories configured on Connect using RPackageRepository, and arbitrary repository URLs in published content.

The R.PositPackageManagerURLRewriting setting takes one of four values:

  • auto (default): Incompatible Posit Package Manager binary URLs are rewritten to use compatible binaries, if they are served by the Package Manager instance. Otherwise, they are rewritten to use source packages. Source package URLs, compatible binary URLs, and other repository URLs are unmodified.
  • force-source: All Posit Package Manager URLs are rewritten to use source packages.
  • force-binary: All Posit Package Manager URLs are rewritten to use binary packages, assuming they are served by the Package Manager instance. Otherwise, they are rewritten to use source packages.
  • none: Disables all modification of Posit Package Manager URLs. Repository URLs from the RPackageRepository.URL Connect configuration setting and from deployed content are used as-is. For example, use none if the configured URLs are correct but the host Linux distribution is not detected as supported by Posit Package Manager.

Example

With the default behavior (R.PositPackageManagerURLRewriting = auto), Posit Connect rewrites incompatible Posit Package Manager binary URLs and leaves all other URLs unmodified. For example, on Ubuntu 22.04 (Jammy):

  • https://packagemanager.posit.co/cran/latest is unmodified, because it installs source packages.
  • https://packagemanager.posit.co/cran/__linux__/jammy/latest is unmodified, because it installs compatible binary packages.
  • https://packagemanager.posit.co/cran/__linux__/focal/latest is rewritten to https://packagemanager.posit.co/cran/__linux__/jammy/latest, because it installs binary packages compiled for a different version of Ubuntu.

To rewrite all URLs to install source packages, use:

; /etc/rstudio-connect/rstudio-connect.gcfg
[R]
PositPackageManagerURLRewriting = force-source

To rewrite all URLs to install compatible binaries:

; /etc/rstudio-connect/rstudio-connect.gcfg
[R]
PositPackageManagerURLRewriting = force-binary