Site icon R-bloggers

Using the R-Universe

[This article was first published on Pachá, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Using the R-Universe

The R-Universe, created by Jeroen Ooms, provides a very simple way to create personal CRAN-like repos, which means a way to show your collection of tools in use to the community.

In addition, you can use it to publish articles by using rmarkdown, an R package that allows you to write text and code, and generate a PDF document even with the templates required for the journal where you want to publish.

To install leontief or any other package from my R-Universe section, you can do this:

# Install new leontief version
install.packages("leontief", repos = "https://pachadotdev.r-universe.dev")

Here are some universes that you can add permanently to your configuration:

# Enable some universes
options(repos = c(
    pachadotdev = 'https://pachadotdev.r-universe.dev',
    tidyverse = 'https://github.com/r-universe/tidyverse',
    rlib = 'https://github.com/r-universe/r-lib',
    tidymodels = 'https://github.com/r-universe/tidymodels',
    rspatial = 'https://github.com/r-universe/r-spatial'
    CRAN = 'https://cloud.r-project.org'))

Creating your own R-Universe

This is particularly useful if you teach courses and you provide, for example, data packages for your students, or if you have packages that you don’t mind sending to CRAN.

In order to join the R-Universe, you need a GitHub profile, and a very good reference to start with Git and GitHub is Happy Git and GitHub for the useR.

For example, tradepolicy is a repository where I have all the codes to reproduce the results from [An Advanced Guide to Trade Policy Analysis]. It is of my interest to list the R packages used there, and in other repositories, so that in the R-Universe other users can easily discover the tools I use.

When you visit the R-Universe you’ll see this landing where you have to click ‘Setup’.

Then you have to select you personal profile (or an organizational account if you have authorization).

Now you can chose all your repositories or just a few. I’ll pick just gravity and tradepolicy, and a few others and then I clicked ‘Install’.

You’ll be asked to confirm R-Universe access to your repositories.

Once it’s ready, you’ll see this

And the URL to your repository will be of the form

https://githubusername.r-universe.dev/
(https://pachadotdev.r-universe.dev/ in my case)

A few minutes after setting it up, the site shall look like this:

Please notice that the repositories that I’ve added are R packages, you can just add a list of packages (i.e. ‘I use dplyr, haven, etc’) to R-Universe if you create a repository with a packages.json file.

This is how to add a list of your favourite packages to the R-Universe:

  1. Go to github.com and create a new repository

  1. Name your repository “universe” (or any other name), set is as public and with a suitable license (I like Apache license) and proceed with the steps from the image. The specific steps are

  1. Create a new file packages.json containing your packages

Here’s the template text that I used:

[
  {
    "package": "tradepolicy",
    "url": "https://github.com/pachadotdev/tradepolicy"
  },
  {
    "package": "leontief",
    "url": "https://github.com/pachadotdev/leontief"
  },
  {
    "package": "tradestatistics",
    "url": "https://github.com/ropensci/tradestatistics"
  },
  {
    "package": "gravity",
    "url": "https://github.com/pachadotdev/gravity"
  },
  {
    "package": "arrow",
    "url": "https://github.com/apache/arrow"
  },
  {
    "package": "RVAideMemoire",
    "url": "https://github.com/pachadotdev/RVAideMemoire"
  }
]
  1. If you added a few repositories to R-Universe, add the newly created universe repo, otherwise you are ready

To leave a comment for the author, please follow the link and comment on their blog: Pachá.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.