Using pak for R and RStudio¶
Recent changes to the R 4.6.1 and RStudio 2026 setup
on Apocrita have opened up the possibility to use the
pak package installer.
pak installs R packages from CRAN, Bioconductor, GitHub, URLs, Git
repositories, local files and directories. It is an alternative to
install.packages() and devtools::install_github().
Installing pak into your personal library¶
pak can be installed into your current personal library like so:
install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
pak::pak_install_extra()
Using pak¶
Once pak is available, it offers many powerful features for R package
management. Below are just a few examples, but please review the
official documentation for
more detailed information.
pak cache¶
Pak maintains a cache so once you install a package, it will cache it, making future installs of that same package faster. The default location for this cache on Apocrita is:
${HOME}/.cache/R/pkgcache/pkg
You may need to clean your
package cache from time to time if you have installed a lot of packages using
pak. You could also consider storing it in a different location (see the
official documentation
for more information).
Installing packages from CRAN and Bioconductor¶
This is as simple as running:
pak::pkg_install("package")
For example, to install tibble from CRAN:
pak::pkg_install("tibble")
Installing packages from external GitHub repositories¶
Clear pak cache to resolve download errors
When using pak to install R packages from GitHub as detailed below, you
may sometimes see errors such as:
✖ Failed to download package 1.0.0 (source)
✖ Failed to download 1 package.
Error:
! error in pak subprocess
Caused by error:
! Failed to download package from `https://api.github.com/repos/org/package/zipball/536f1033d6de7c957f26a1f403f81efbd825e0db`.
Type .Last.error to see the more details.
To resolve such errors, please
clean your pak cache:
pak::pak_cleanup(
package_cache = TRUE,
metadata_cache = TRUE,
pak_lib = TRUE,
force = FALSE
)
The popular devtools R package previously offered installation helpers such as
install_github() to install R packages directly from GitHub.
v2.5.0 of devtools
deprecated most of these wrappers in favour of using pak:
Package installation functions are now deprecated:
install_bioc(),install_bitbucket(),install_cran(),install_deps(),install_dev(),install_dev_deps(),install_git(),install_github(),install_gitlab(),install_local(),install_svn(),install_url(),install_version(),update_packages(),dev_package_deps(),github_pull(), andgithub_release(). We now recommendpak(https://pak.r-lib.org/) for general package installation. See?install-deprecatedfor migration guidance.
Attempts to use these deprecated commands with devtools v2.5.0 or newer will
throw errors:
Warning messages:
1: `install_github()` was deprecated in devtools 2.5.0.
i Please use pak::pak("user/repo") instead.
For example, to install the tibble R
package directly from GitHub, you would run:
library(pak)
pak::pkg_install("tidyverse/tibble")
For more detailed information, please see the
official pak documentation.
sysreqs_check_installed¶
You can check if the system libraries required for packages installed in your
library are present using
sysreqs_check_installed().
E.g.:
> sysreqs_check_installed()
system package installed required by
-------------- -- -----------
cmake ✔ fs, nloptr, s2
default-jdk ✔ rJava
gdal-bin ✔ sf, terra
git ✔ credentials, gitcreds, remotes
jags ✔ rjags
libabsl-dev ✔ s2
libcairo2-dev ✔ Cairo
libcurl4-openssl-dev ✔ curl, RCurl
libfftw3-dev ✔ qqconf
libfontconfig1-dev ✔ systemfonts
libfreetype6-dev ✔ ragg, systemfonts, textshaping
libfribidi-dev ✔ textshaping
libgdal-dev ✔ sf, terra
libgeos-dev ✔ sf, terra
libgit2-dev ✔ gert
libglpk-dev ✔ igraph
libgsl0-dev ✔ gsl
libharfbuzz-dev ✔ textshaping
libhdf5-dev ✔ hdf5r
libicu-dev ✔ stringi
libjpeg-dev ✔ jpeg, ragg
libnetcdf-dev ✔ ncdf4
libpng-dev ✔ png, ragg, svglite
libproj-dev ✔ sf, terra
librsvg2-dev ✔ rsvg
libsqlite3-dev ✔ sf, terra
libssl-dev ✔ curl, openssl, s2
libtiff-dev ✔ ragg
libudunits2-dev ✔ units
libuv1-dev ✔ fs
libwebp-dev ✔ ragg
libx11-dev ✔ clipr
libxml2-dev ✔ igraph, XML, xml2
make ✔ fs, h5mread, haven, httpuv, minqa, OpenMx, RcppParallel, RCurl, rhdf5, rhdf5filters, rJava, rpf, sass, StanHeaders
pandoc ✔ bookdown, knitr, pkgdown, reprex, rmarkdown, StanHeaders
perl ✔ GetoptLong
python3 ✔ argparse, reticulate
zlib1g-dev ✔ haven, httpuv
These system-level packages come from inside of the container that R 4.6.1 and RStudio 2026 run from. If anything is missing, please raise a ticket and we can look to add it into the container.
Using pkg_sysreqs to check system-level libraries¶
You can poll what system-level dependencies need to be installed for any package
using the pkg_sysreqs()
command. For example, for devtools:
library(pak)
pkg_sysreqs("devtools", upgrade = TRUE, dependencies = NA, sysreqs_platform = NULL)
Which outputs:
✔ Updated metadata database: 4.28 MB in 8 files.
✔ Updating metadata database ... done
── Install scripts ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Ubuntu 24.04 ──
apt-get -y update
apt-get -y install libx11-dev git libcurl4-openssl-dev libssl-dev cmake make libuv1-dev libgit2-dev zlib1g-dev pandoc libfreetype6-dev libjpeg-dev \
libpng-dev libtiff-dev libwebp-dev libicu-dev libfontconfig1-dev libfribidi-dev libharfbuzz-dev libxml2-dev
── Packages and their system dependencies ────────────────────────────────────────────────────────────────────────────────────────────────────────────
clipr – libx11-dev
credentials – git
curl – libcurl4-openssl-dev, libssl-dev
fs – cmake, libuv1-dev, make
gert – libgit2-dev
gitcreds – git
httpuv – make, zlib1g-dev
knitr – pandoc
openssl – libssl-dev
pkgdown – pandoc
ragg – libfreetype6-dev, libjpeg-dev, libpng-dev, libtiff-dev, libwebp-dev
rmarkdown – pandoc
sass – make
stringi – libicu-dev
systemfonts – libfontconfig1-dev, libfreetype6-dev
textshaping – libfreetype6-dev, libfribidi-dev, libharfbuzz-dev
xml2 – libxml2-dev
The output of this report can help us to identify which system-level dependencies might need to be added into the container.
If you have any questions regarding the use of pak, please contact us on our
Slack channel (QMUL users only), or
by sending an email to
its-research-support@qmul.ac.uk which
is handled directly by staff with relevant expertise.
Title image: pak GitHub Repository
