Skip to content
Git

Configuration

When using the default CRAN repository mirrors on Linux, R packages are downloaded as source packages (with https://cloud.r-project.org as the default CRAN mirror). To obtain binary packages tailored for your Linux distribution, you must explicitly change the repository setting to one that provides binaries.

This change can be applied system-wide, at the user level or project level.

See section "Repository Configuration" for how to configure the repository for each of these levels.

There are two ways to configure the repository for your R environment:

  • (1) explicitly
  • (2) implicitly (recommended)

Option (1) means you hardcode the full path to the index files of your respective architecture and operating system, for example: https://cran.rpkgs.com/amd64/noble/latest. This works for any R installation on the respective OS/arch combination out of the box.

(Option 2) The alternative is to use only https://cran.rpkgs.com. The advantage is that you do not need to lookup the exact URL for your operating system and architecture and can use the same repository source in a project on clients with different operating systems seamlessly.
This way requires the HTTP user agent to be configured in a way that it returns the information about the OS, its version and architecture of the client sending the requests to cran.rpkgs.com. To configure the HTTP user agent, the following R commands must be run on startup of every R session, i.e. they need to be present in ~/$R_HOME/Rprofile.site (or any other valid R profile file):

os_release <- readLines("/etc/os-release")
name_line <- grep("^NAME=", os_release, value = TRUE)
name <- sub('^NAME="?([^"]*)"?$', '\\1', name_line)
version_line <- grep("^VERSION_ID=", os_release, value = TRUE)
version <- sub('^VERSION_ID="?([^"]*)"?$', '\\1', version_line)
options(HTTPUserAgent = sprintf("R/%s (%s) (%s)", getRversion(), paste(name, version), paste(R.version["platform"], R.version["arch"], R.version["os"])))

This should result in the following output in an R session:

getOption("HTTPUserAgent")
[1] "R/4.3.3 (Ubuntu 24.04) (x86_64-pc-linux-gnu x86_64 linux-gnu)"

The URL scheme used to store the binaries is identical operating systems and only differs in the OS and architecture identifiers.

For example, the URL for Alpine Linux 3.21 for the arm64 architecture would be

https://cran.rpkgs.com/arm64/alpine321/latest

The architecture identifiers are:

  • arm64 | aarch64
  • amd64 | x86-64

The OS identifiers are:

  • jammy (Ubuntu 22.04)
  • noble (Ubuntu 24.04)
  • rhel8 (RedHat Enterprise Linux 8)
  • rhel9 (RedHat Enterprise Linux 9)
  • rhel10 (RedHat Enterprise Linux 10)
  • alpine320 (Alpine Linux 3.20)
  • alpine321 (Alpine Linux 3.21)
  • alpine322 (Alpine Linux 3.22)

To configure the default R repository for all users of a system, create/edit $R_HOME/etc/Rprofile.site.
The location of this file depends on how R has been installed. To locate it, run

Terminal window
R -q -e "paste0(Sys.getenv('R_HOME'),'/etc/Rprofile.site')"

At the bottom of the file add:

options(repos = c(CRAN = "<URL>"))

To change the default repository option for a specific user, add the line from above to ~/.Rprofile.

To change the default repository option for a specific project, add the line from above to .Rprofile in the project root directory in which R is started.

When starting R, execute getOption("repos") to verify the repository is correctly configured.

Some R packages are only compatible with the R minor version they have been built with (e.g. R 4.4), or one of the adjacent versions (e.g. R 4.3.). This is because they are making use of specific bindings to the R API, which may change between minor versions. While building the packages works, they error out when loaded.