= Installing R Packages = The main strength of R is the ecosystem of '''R packages'''. In many instances, users are recommended to install packages within an R REPL. For [[Linux]] users, it is possible to use the system package manager instead. <> ---- == Example == {{{ # To install install.packages("tidyverse") # To update update.packages() # To then use library(tidyverse) }}} ---- == Alternative Interactive Installations == === Install from Source Code === To install from source code, thereby compiling any binaries as necessary, try: {{{ install.packages("path/to/tidyverse_2.0.0.tar.gz", repos=NULL) }}} === Install from GitHub === There are several R packages that exist as toolchains for installing other packages directly from !GitHub. As an example, the `devtools` package: {{{ install.packages("devtools") devtools::install_github("tidyverse/ggplot2") }}} As another example, the `pak` package: {{{ 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("tidyverse/ggplot2") }}} ---- == System Package Managers == === Ubuntu === Follow the instructions at [[https://cran.r-project.org/bin/linux/ubuntu/]]. Namely: {{{ # minimal requirements sudo apt install --no-install-recommends software-properties-common dirmngr # add the PPA signing key # Fingerprint: E298A3A825C0D65DFD57CBB651716619E084DAB9 wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc # add the PPA sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" # install R sudo apt install --no-install-recommends r-base # install R packages sudo apt install --no-install-recommends r-cran-tidyverse }}} === Arch === While some R packages have corresponding AUR PKGBUILDS, they are generally poor quality. Instead either follow the instructions at [[https://github.com/dvdesolve/ArchRPkgs#binary-repository]] or use that repository's PKGBUILDs to build the R packages directly. ---- CategoryRicottone