iTranslated by AI
Modern R Installation: rig, pak, and p3m
Introduction
Is everyone using Rust?
The installation experience for Rust is great, isn't it? Switching the version of Rust itself effortlessly with rustup and being able to manage packages with Cargo by default.
Rust-like tools in other languages (?)
Perhaps because the Rust experience is so superior, I see Rust-like things in other languages too. The official Julia version management tool is named juliaup.
It's not just that the name is similar to rustup; it actually seems to reuse some of the source code. The top of the juliaup installation shell script mentions that it uses a modified version of the rustup installation script.
$ curl -fsL https://install.julialang.org | head
#!/bin/sh
# shellcheck shell=dash
# This script is adapted for juliaup from the original rustup repository
# over at https://github.com/rust-lang/rustup. Names and urls have been
# changed during the adaptation.
# This is just a little script that can be downloaded from the internet to
# install juliaup. It just does platform detection, downloads the installer
# and runs it.
Of course, juliaup is also made with Rust.
In Python, Rye, which was released by Armin Ronacher this year, was created exactly with the motivation of "wanting something like Rust in the Python world."
This is also made with Rust.
R Installation Manager: rig
The next thing you might wonder is whether there is something similar for R, right? Here is "The R Installation Manager" called rig[1].
I'd like you to read the README for details, but rig is a CLI tool that supports Windows (amd64), macOS (amd64 and ARM64), and Linux (certain distributions, amd64 and arm64), providing convenient features for managing R. For example, you can switch between multiple versions of R with a single command.
As a point of caution, rig can only manage R versions installed via rig; you cannot use R versions that are already installed. Therefore, if you use rig, you need to install rig before installing R.
Installing R with rig
Let's try out rig on Windows. Here, we'll start by using Windows Sandbox and installing rig via winget[2].
Let's search for rig using winget search. Since it's developed by Posit, it is registered as posit.rig in winget-pkgs[3].
> winget search posit.rig
Name Id Version Source
------------------------------
rig Posit.rig 0.6.0 winget
It looks like version 0.6.0 is currently available for installation. Let's install it.
> winget install posit.rig
Found rig [Posit.rig] Version 0.6.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/r-lib/rig/releases/download/v0.6.0/rig-windows-0.6.0.exe
██████████████████████████████ 4.68 MB / 4.68 MB
Successfully verified installer hash
Starting package install...
Successfully installed
It's a small tool, so it was installed in a few seconds. Next, let's install R using the rig add command. If you don't specify a version, the latest version will be installed.
> rig add
[INFO] Cleaning leftover registry entries
[INFO] Downloading https://cran.rstudio.com/bin/windows/base/R-4.3.2-win.exe -> C:\Users\WDAGUT~1\AppData\Local\Temp\rig\x86_64-R-4.3.2-win.exe
[INFO] Installing C:\Users\WDAGUT~1\AppData\Local\Temp\rig\x86_64-R-4.3.2-win.exe
[INFO] Adding R-4.3.2 -> C:\Program Files\R\R-4.3.2
[INFO] Adding R-release -> 4.3.2 alias
[INFO] Setting default CRAN mirror
[INFO] Installing pak for R 4.3.2 (if not installed yet)
[INFO] > Installing package into 'C:/Users/WDAGUtilityAccount/AppData/Local/R/win-library/4.3'
[INFO] > (as 'lib' is unspecified)
[INFO] > trying URL 'https://r-lib.github.io/p/pak/stable/win.binary/mingw32/x86_64/bin/windows/contrib/4.3/../../../../../../../mingw32/x86_64/pak_0.7.1_R-4-3_x86_64-mingw32.zip'
[INFO] > Content type 'application/zip' length 8615600 bytes (8.2 MB)
[INFO] > ==================================================
[INFO] > downloaded 8.2 MB
[INFO] >
[INFO] >
[INFO] > The downloaded binary packages are in
[INFO] > C:\Users\WDAGUtilityAccount\AppData\Local\Temp\RtmpMdsPJj\downloaded_packages
R 4.3.2, the latest version as of today, has been installed. Next, let's install R 4.2 with rig add 4.2.
> rig add 4.2
[INFO] Cleaning leftover registry entries
[INFO] Downloading https://cran.rstudio.com/bin/windows/base/old/4.2.3/R-4.2.3-win.exe -> C:\Users\WDAGUT~1\AppData\Local\Temp\rig\x86_64-R-4.2.3-win.exe
[INFO] Installing C:\Users\WDAGUT~1\AppData\Local\Temp\rig\x86_64-R-4.2.3-win.exe
[INFO] Adding R-4.2.3 -> C:\Program Files\R\R-4.2.3
[INFO] Setting default CRAN mirror
[INFO] Installing pak for R 4.2.3 (if not installed yet)
[INFO] > Installing package into 'C:/Users/WDAGUtilityAccount/AppData/Local/R/win-library/4.2'
[INFO] > (as 'lib' is unspecified)
[INFO] > trying URL 'https://r-lib.github.io/p/pak/stable/win.binary/mingw32/x86_64/bin/windows/contrib/4.2/../../../../../../../mingw32/x86_64/pak_0.7.1_R-4-2_x86_64-mingw32.zip'
[INFO] > Content type 'application/zip' length 8159272 bytes (7.8 MB)
[INFO] > ==================================================
[INFO] > downloaded 7.8 MB
[INFO] >
[INFO] >
[INFO] > The downloaded binary packages are in
[INFO] > C:\Users\WDAGUtilityAccount\AppData\Local\Temp\RtmpmWhH9Q\downloaded_packages
R 4.2.3, the final version of R 4.2.X, has been installed. You can list the installed versions of R using the rig list command. The version marked with * is the currently selected version.
> rig list
* name version aliases
------------------------------------------
4.2.3
* 4.3.2 release
Running the rig run command starts R 4.3.2, the currently selected version. Similarly, running R from cmd.exe or R.bat from PowerShell will execute the selected R version. As you can infer from the fact that R is actually R.bat, rig changes the version of R called by R by overwriting the contents of R.bat.
On macOS and Linux, the same functionality is achieved by rewriting symlinks.
When installing R on Windows, old version files tend to remain when a new version is added, which I always found troublesome because of having to reset paths. Using rig is very convenient as you can switch between them with rig commands.
pak: The Jack-of-all-trades for R Package Installation
Did you notice in the log when installing R with rig earlier that something called pak was also installed? pak is a multi-functional package for installing R packages.
It has various features, so please check the documentation for details. The easiest function to remember is pak::pak(), which, in addition to simple installations from the default repository like install.packages(), can also perform installations from GitHub like remotes::install_github().
Recently, in the READMEs of packages like dplyr, the function written for installing development versions has switched from remotes::install_github() to pak::pak().
# Install dplyr from the HEAD of the tidyverse/dplyr repository on GitHub
pak::pak("tidyverse/dplyr")
If you are developing R packages on GitHub, you might be using r-lib/actions/setup-r-dependencies in GitHub Actions to install dependent R packages. pak is used within this action. Usually, when installing R packages on Linux, you often have to install system dependencies outside of R, but pak can check the dependencies of each package, execute commands, and automatically install system dependencies. The reason you don't have to worry about system dependencies even when using an Ubuntu runner in GitHub Actions is thanks to this feature.
pak does have some minor drawbacks, such as being difficult to debug because it doesn't show build logs during source installation, but it is multi-functional and useful in various situations, so please take a look at the official documentation.
The renv package, which reached version 1.0.0 a few months ago and enables per-project package locking, also has an option to use pak as a backend.
p3m: A Strong Ally for Binary Package Installation
Posit Package Manager (formerly RStudio Package Manager) is a closed-source product from Posit. It allows you to create snapshots of repositories like CRAN and build your own package repositories. For R users, the fact that it provides binary packages for certain Linux distributions is also a welcome feature.
There is a public service for this product, operated by Posit, that anyone can access. The r-lib/actions/setup-r-dependencies mentioned in the pak section uses this repository to speed up R package installation on Ubuntu.
This service used to be officially named RStudio Public Package Manager, but it was often referred to as RStudio Package Manager or by its abbreviation, RSPM, which I think led to some naming confusion.
Furthermore, it was also confusing because, despite evoking the familiar RStudio IDE, it is actually a completely separate service (at least, I initially thought it was a built-in feature of the RStudio IDE or something).
Perhaps reflecting on that, the simple abbreviation "P3M" has recently come into use[4], and it has finally become accessible via the p3m domain.
Previous URLs remain valid, but this short and clear URL is expected to become the mainstream one going forward.
P3M has recently undergone significant functional enhancements, such as starting to provide binary packages for Debian and macOS, and it is likely to become an even stronger ally for the binary installation of R packages.
R installed via rig has P3M set as the default repository (using the traditional URL), so you can reap the benefits of P3M without even being aware of it.
options("repos")
#> $repos
#> P3M
#> "https://packagemanager.posit.co/cran/latest"
#> CRAN
#> "https://cloud.r-project.org"
-
Originally it was rim, short for R Install Manager, but it was renamed to rig probably because the name overlapped with an R package named rim that exists on CRAN. ↩︎
-
Here is how to introduce winget onto Windows Sandbox. https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox ↩︎
-
I registered it myself. https://github.com/microsoft/winget-pkgs/pull/108337 ↩︎
-
It is already referred to as P3M in the documentation for rig (which sets P3M as the R repository) and pak (which has associations such as previously downloading Linux system dependency information from P3M). ↩︎
Discussion