R Repositories


R is a language used for statistical analysis and machine learning. R and R Studio both allow you to install packages from repositories, allowing convenient access to a large number of packages from the remote Comprehensive R Archive Network (CRAN).

Sonatype Nexus Repository takes advantage of the packages in the official CRAN repository and other public repositories without incurring repeated downloads of packages.

You can publish your own packages to a private repository in a hosted R repository and then combine the remote and private repositories to R as a repository group, which is a repository that merges and exposes the contents of multiple repositories in one convenient URL. This allows you to reduce time and bandwidth usage for accessing R packages as well as more easily share your packages within your organization.

This format is disabled by default in legacy High Availability Clustering (HA-C) environments.

Supported File Types

Proxy R repositories support any file type. 

Hosted and group R repositories only support files with a .gz extension.

If your proxy R repository is part of a group, you will only be able to request files with a .gz extension through the group. You will need to request any other file type directly from the proxy repository.

Proxying R Repositories

You can set up an R proxy repository to access a remote repository location.

To proxy an R repository, create a new r (proxy) as shown in the documented example in Repository Management in detail. Minimal configuration steps for R proxy are:

Hosting R Repositories

Hosted R repositories only support files with a .gz extension.

Creating an R hosted repository allows you to register packages in the repository manager. The hosted repository acts as an authoritative location for these components.

To add a hosted R repository, create a new repository with the recipe r (hosted) as shown in the documented example in  Repository Management. Minimal configuration steps for R hosted are:

  • Define Name, e.g.  r-hosted
  • Select Blob store for Storage

Deploying Packages to R Hosted Repositories

Hosted R repositories only support files with a .gz extension.

Upload with Nexus Repository Manager UI

To upload packages to a hosted R repository, upload components through the user interface.

R format requires to specify proper package path location inside a repository. You can do this by using the package path field  in the Upload form. More details about the package path could be found on the official site (https://cran.r-project.org) in the Related Directories section.   

Several examples for package path field:

  • For sources (Package path):  src/contrib
  • For Windows binary (Package path): bin/windows/contrib/3.6
  • For OS X binary (Package path): bin/macosx/el-capitan/contrib/3.6

Upload by HTTP POST

The following example uses the curl command to upload an example_1.0.0.tar.gz file to a hosted R repository (fill in <> with your respective data) :

curl -v --user '<username>:<password>' --upload-file example_1.0.0.tar.gz http://<host>:<port>/repository/<repository_name>/src/contrib/example_1.0.0.tar.gz

The package will now be contained within your hosted repository and consumers can install the package as described in Configuring R Client. 

R Repository Groups

Group R repositories only support files with a .gz extension.

A repository group is the recommended way to expose all your R repositories from the repository manager to your users, with minimal additional client-side configuration. A repository group allows you to expose the aggregated content of multiple proxy and hosted repositories as well as other repository groups with one URL in tool configuration. This is possible by creating a new repository with the r (group) recipe as shown in the documented example in  Repository Management. Minimal configuration steps for R group are:

  • Define Name, e.g.  r-group
  • Select Blob store for Storage
  • Add R repositories to the Members list in the desired order

If you request a file from a group and that file is present in more than one group member, the group will return merged data.

Configuring R Client

Once you have set up your repositories for R packages, you can adjust your R startup script to use your repository URLs. A suggested way to do so is to create a  .Rprofile  file and include a snippet similar to the following in it:

## Default repo

local({r <- getOption("repos")
	r["Nexus"] <- "http://<host>:<port>/repository/<repository_name>"


This will set your default R repository as the group repository. For more information on adjusting R startup files, please visit the
mini guide on the r-bloggers.

Also, it is possible to install an R package directly from the R client console:

install.packages("example", repos="http://<host>:<port>/repository/<repository_name>", type="<package_type>")

<package_type> is optional and accepts values of  source  and  binary. If left off the console command, it defaults to  binary.

If anonymous access to the repository manager is disabled, you have to specify the credentials for the accessing the repository manager as part of the URL like  http://<username>:<password>@<host>:<port>/repository/<repository_name>.

Downloaded packages are cached, do not have to be retrieved from the remote repositories again and can be inspected in the user interface.