Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

HOWTO: Create and Upload CRAN Packages to a Private Repository in ProGet

view on GitHub

ProGet let's you set up private repositories for your internal R packages that will allow you to publish, store, and share them within your organization.

This guide will walk you through the process of setting up a CRAN "Feed" in ProGet as a private, custom repository. We'll also cover how to build, upload, and install packages from this repository.

Step 1: Create and Name a CRAN Feed

We'll begin by creating a CRAN feed to host your R packages. Navigate to "Feeds" and "Create New Feed". Then select "CRAN Packages".

Now select "No Connectors (Private packages only)" as this feed will be intended as a private repository.

From here, we name our feed. For this example, we will call it internal-cran, and then click "Create Feed".

You'll then see several options related to ProGet's Vulnerability Scanning and Blocking features. These are only for users looking to use third-party OSS packages. Leave these boxes unchecked, and select "Set Feed Features". You will then be directed to the new internal-cran feed, currently empty.

Step 2: Create an API Key

Next, we'll create an API Key allowing our local client to authenticate to our internal-cran feed. This allows us to upload and install packages from the feed.

When creating the API key, fill in the fields by selecting "Feeds (Use Certain Feeds)" as the "Feed Type" and selecting the internal-cran feed. Then set the API key. You can use any alphanumeric sequence, or just leave it blank to autogenerate one. Make sure the "View/Download" and "Add/Repackage" boxes are checked, and then select "Save".

Step 3: Build Your R Package

Next, we will build our R packages. More information on developing these can be found in the official documentation. The commands in this step can be performed in either your R CLI or the RStudio console.

To build your package, you'll first need devtools installed. To do this enter:

install.packages("devtools")
library(devtools)

Or in the RStudio interface, you can also navigate to "Tools" > "Install Packages..." and enter devtools in the "Packages" field.

If you're using a CLI you're also need to make sure that the current working directory is set to the folder that your package files are located in (e.g. DESCRIPTION, NAMESPACE and .r files) by entering setwd("path/to/package")

Before building, we also recommend generating documentation by entering devtools::document() and then running a check with devtools::check() to make sure your project is free from errors.

Then build your package by entering:

devtools::build()

Or in RStudio, you can alternatively navigate to the "Build" tab and select "Build Source Package".

Your .tar.gz R package is then built, and saved to the same location as your project folder.

Step 4: Upload Your Package to ProGet

To upload your package to your internal-cran CRAN feed, you can use pgutil.

pgutil will require some minor configuration before use. This includes configuring your ProGet instance and API key as a source by running:

$ pgutil sources add --name=Default --url=«proget-url» --api-key=«api-key»

For example, adding the ProGet instance https://proget.corp.local/ with the API Key abc12345 you would enter:

$ pgutil sources add --name=Default --url=https://proget.corp.local/ --api-key=abc12345

Now upload your packages by entering:

$ pgutil packages upload --feed=«feed-name» --input-file=«path-to-package»

For example, to upload the package my-package-1.0.0.0000.tar.gz stored at C:\development\cran_packages\ to your internal-cran feed you would enter:

$ pgutil packages upload --feed=internal-cran --input-file==C:\development\cran_packages\my-package-1.0.0.0000.tar.gz

Your package will then be uploaded to the internal-cran feed.

Step 5: Add the Feed to Local R Environments

To install R packages you have published to your internal-cran feed, you'll need to add the feed to your local R environments. For this, you will need the feed's URL. This is found at the top right of the feed's page.

Then, any time you want to install a package, take the internal-cran feed URL and the API key you created in "Create an API Key", and in enter:

install.packages("«package-name»", repos="«feed-url»")

For example, to install the package devtools from http://proget.corp.local/cran/internal-cran/ you would enter:

install.packages("devtools", repos="http://proget.corp.local/cran/internal-cran/")

However, to avoid having to type in the repo URL every time, you can set your internal-cran feed as a custom repository. This will configure R to look first at the specified URL for packages, instead of the default CRAN repository. You can do this by entering:

options(repos = c(«repository-name» = "«feed-url»"))

For example, to create a custom repository with the name ProGet that points to http://proget.corp.local/cran/internal-cran/ you would enter:

options(repos = c(ProGet = "http://@proget.corp.local/cran/internal-cran/"))

In the above example, we name the custom repository ProGet, though you can choose any name you prefer.

You can also configure this in RStudio by navigating to "Tools" > "Global Options" > "Packages" and selecting "Change".

And then entering your Feed URL in the "Custom" field.

Now you can install your internal packages by entering:

install.packages("my-package")

Or, in RStudio, by navigating to "Tools" > "Install Packages..." and enter the package name in the "Packages" field.

You can confirm that your local R environment is configured with your CRAN feed by entering:

getOption("repos")

This should list all repositories connected. If your ProGet instance is at the top, this indicates that it is set as the primary repository source for packages.