Posit Package Manager for Linux R Binaries

[This article was first published on tshafer.com, 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.

I’ve been getting a lot of use recently from the Posit (née RStudio) Package Manager (PPM), because it offers freely available R package binaries for quite a few Linux distributions—including common ones I tend to see in Docker containers (rocker) and ‘the cloud’ (Amazon Linux 2). Recent versions of renv seem to take advantage of these binaries, too.

Binary packages can cut package install times by an order of magnitude, since they come precompiled. Many popular packages, including data.table and dplyr, are more or less R wrappers around C or C++ code at this point in an effort to make things fast, and so installing/compiling a package like dplyr from source can take minutes. That’s fine once or twice, but it’s not fine when I regularly rebuild containers or run package checks with GitHub Actions.

It’s pretty easy to get running with PPM once you know where to look in the documentation, and it basically comes down to two steps.

Get a repo URL for your Linux distribution

Posit offers different endpoints for the various Linux distributions. To find yours:

  1. Navigate to the PPM setup page.
  2. Choose your Linux distribution. At the right-hand side of the header, click “Source” and choose from the drop-down menu.
  3. Make sure the “Repository URL” setting is “Latest”. This is the default.
  4. Copy the URL for your distribution. E.g., the URL for Ubuntu 22.04 is https://packagemanager.posit.co/cran/__linux__/jammy/latest.

Configure R to use your new endpoint

It’s easy to configure R to use the PPM endpoint by setting or changing a couple of values in .Rprofile:

  1. Set a header to tell Posit your R configuration. The header passes along your version of R and a few other platform details.

    r options(HTTPUserAgent = sprintf( "R/%s R (%s)", getRversion(), paste( getRversion(), R.version["platform"], R.version["arch"], R.version["os"] ) ))

  2. Set the PPM as your CRAN source. CRAN is generally the default package source and is configured as part of the “repos” option. E.g,. for the same Ubuntu configuration as above, we would set:

    r options(repos = c(CRAN = "https://packagemanager.posit.co/cran/__linux__/jammy/latest"))

By setting these values in .Rprofile they will generally propagate to all your R sessions and, if the stuff I’m doing is an indication (Docker, GitHub Actions, Databricks1, etc.), you might save a good bit of time.

  1. Ugh. ↩︎

This post is kindly republished by R-bloggers.

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

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)