How to Upload R Packages to Artifactory
A Quick-Start Guide with Screenshots
CRAN on Artifactory
Let’s say you want to upload your R packages somewhere so that others can download them. An easy way to do this is by using Artifactory to host a local CRAN repository. In the following guide I’ll show you how you can do this yourself with a minimum amount of fuss (mainly through visual interfaces), although of course everything is scriptable when you want to start automating more of this.
Step 0: Install RStudio
This is the standard R IDE, so you probably already have it installed. If you don’t, download it here: https://rstudio.com/
Step 1: Create a CRAN Repository in Artifactory
Navigate to the Artifactory UI in your web browser and go the administration tab.
From there, go to Repositories, Repositories, Local and then select CRAN as the Package Type. Remember the name of your repo because you’ll use it later to upload your files! If you don’t have access to the administration page, you might have to ask one of your Artifactory admins to create the CRAN repo for you. For more information, you can look at the official documentation.
Step 1: Create your R Package
You probably already have the R package created if you found this blog post, but if you don’t have it packaged up quite yet, there’s a classic blog post about this here: https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/
Step 2: Build your Package
Once you have your R package, you should open it up with RStudio. Here you can open up the Rproj file so that RStudio knows that you’re building a package.
Select “Build Source Package” from the “Build” menu. If you have a lot of files that need to be compiled for specific platforms, then you can choose “Build Binary Package” , but you will have to input the relevant data when you upload it to Artifactory. The result of this operation will be a zipped file that you can then upload to your CRAN on Artifactory.
Step 3: Upload the package to Artifactory
First, find where your package tarball was generated using RStudio. It should be sitting beside the directory containing your package source.
Navigate to your Artifactory web app. Then, open up the artifact repository window on Artifactory and hit the deploy button.
Select your CRAN repo from the “Target Repository” menu. It should display as “Package Type: R CRAN” as below. Then, select the package file you generated or drag it into this window. Hit deploy when you’re satisfied.
Now you should be able to see your package within the tree browser view within the Artifact Repository Browser.
Step 4: Check to see if you can install from your Artifactory CRAN
First, you want to remove the example package from your R library by running remove.packages("sample.r.package")
. Then, you can install it from your local CRAN by running install.packages("sample.r.package", repos=c("http://my_artifactory.com/artifactory/my-cran/"))
. Hopefully, everything has installed correctly, and you can now share your package with the rest of your organization!
Congratulations! You uploaded your first package to Artifactory!
Now that you manage you have your package in your own personal CRAN, the world is your oysteR! Tell everyone at your company about your package, and they can easily install it without having to use devtools. Nice!
Your next step in your jouRney is to start uploading binary packages to Artifactory. This is where using a package manager like CRAN really shines, since this means that the users of your package won’t have to install complicated toolchains to recompile your package for their own systems. When you’re ready to take your next step, check out the documentation here.