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:
-
Navigate to the PPM setup page.
-
Choose your Linux distribution. At the right-hand side of the header, click “Source” and choose from the drop-down menu.
-
Make sure the “Repository URL” setting is “Latest”. This is the default.
-
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
:
-
Set a header to tell Posit your R configuration. The header passes along your version of R and a few other platform details.
-
Set the PPM URL as your CRAN source.
CRAN
is generally the default package source and is configured as part of the “repos” option.
Put together, you get an addition to .Rprofile
like this:
options(HTTPUserAgent = sprintf(
"R/%s R (%s)",
getRversion(),
paste(
getRversion(),
R.version["platform"],
R.version["arch"],
R.version["os"]
)
))
.ppm <- "https://packagemanager.posit.co/cran/__linux__/jammy/latest"
options(repos = c(CRAN = .ppm))
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, Databricks,1 etc.), you
might save a good bit of time.
-
Ugh. ↩︎