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.
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 and RStudio Connect, a local package repository should be used for both. Specifically, users or administrators should install packages in RStudio Server’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 RStudio 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 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.