Sharing Internal R Packages


There are a number of ways to share a package internally at an organization. This article outlines four of the easiest methods:

Option A: Share a Compressed Folder

  1. Build the package into a source / tar file. This can be done in the IDE:

  1. Put the tar file in a shared network location. Users can either download the tar file and then install the package, or install the package directly from the compressed folder on the shared drive:
    install.packages("path/to/tar/file", source = TRUE, repos=NULL)

Option B: Use Git

  1. Put the whole R package (the R folder, namespace file, description, etc) into a git repo (either an internal repo or github).

  • Users can install the package using devtools:


Option C: Use Local Repository

These instructions: provide a framework for setting up a local repository and adding packages. In particular:

  1. Create a local repository, which is just a specific folder structure.
  2. Update the package’s DESCRIPTION file to include:

    Repository: name_of_local_repo
  3. Build the package and move the tar file into the correct location in the local repository.

  4. Update the local repository’s PACKAGE files using tools::write_PACKAGES

Users can install the package with:

install.packages('package_name', source = TRUE, repos=repoURI)

Option D: System Library

If you are using RStudio Workbench (previously RStudio Server Pro), you can make the package automatically available to users by installing the package in the system library. To do so, just use one of the methods above (A-C) and install the package into the system library:

install.packages('my_package', source=TRUE, lib.loc = "/path/to/system/lib", repos=NULL)