If you are administering RStudio Connect in an offline environment, you’ll need to follow certain steps to ensure the R packages used by your team are available in Connect. These steps are different from the process you might have used in the past to provide packages to RStudio.
The first option is to check and see if your networking team will allow outbound access to CRAN, by enabling access to https://cran.rstudio.com. The admin guide contains instructions for configuring RStudio Connect to use an outbound proxy for package downloads. If you are not able to access an online repository, you will need to create and administer your own package repository.
The remainder of this article documents the background information and steps for doing so. The easiest way to administer a package repository for R is using RStudio Package Manager.
Package Library vs Package Repository
A repository is a directory containing uninstalled R source files or platform-specific binaries. A repository contains a
PACKAGES file with important information about the repository’s content.
A library is a directory containing installed R packages.
Though a repository and a library look very similar, they are two distinct entities.
Usually, two steps are required to use an R package:
- The package is installed from a repository into a library using
- The package is loaded from the library for an analysis using
In offline RStudio environments, it is common for administers to skip setting up a local package repository, and instead install packages directly from an online CRAN repository into a system library. The system library - a set of folders - is then moved to the offline environment or located on shared storage. R users access packages from the system library using the
library() function. The administrator tells R to look in the correct directory by defining
R_LIBS_SITE in the
Renviron.site file or using the R function
.libPaths() in the
Offline use of RStudio Connect, however, requires admins to set up a package repository. This requirement is necessary to enable Connect to manage and isolate package dependencies for deployed content. In brief, Connect installs packages from the local repository into private libraries for each piece of deployed content. Individual libraries guarantee that the content will have the correct packages, even if other content on the server requires a different version of the same package. (In practice, the process is optimized to cache packages while guaranteeing the correct versions are always available).
In environments with both RStudio Workbench (previously RStudio Server Pro) and RStudio Connect, a local package repository should be used for both. Specifically, users or administrators should install packages in RStudio Workbench's system library from the local repository. Installing packages into the system library from a different repository can result in a mismatch between Connect and Workbench that will cause deployment failures.
Setting up a local repository
To make the process of creating a local repository easy, we've built a product called RStudio Package Manager. RStudio Package Manager provides a holistic strategy for managing R packages in your organization, and it is built to work with RStudio Workbench and RStudio Connect.
There are open-source alternatives for managing local repositories, including the
packrat R packages. RStudio can not provide support for these open source alternatives.