Code Tools

R

Installing R from Source

The following guide is derived from a Posit guide to installing R from source and is tailored to Debian/Ubuntu distributions of Linux:

sudo apt install build-essential cmake libblas-dev \
  gfortran liblapack-dev bzip2 libbz2-dev libreadline-dev \
  libcairo-dev pandoc git libgit2-dev libxt-dev liblzma-dev \
  libcurl4-openssl-dev chromium texinfo texlive texlive-fonts-extra \
  libtiff-dev libjpeg-dev
sudo sed -i.bak "/^#.*deb-src.*universe$/s/^# //g" /etc/apt/sources.list
sudo apt update
sudo apt build-dep r-base
export R_VERSION=4.4.1
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
./configure \
  --prefix=/opt/R/${R_VERSION} \
  --enable-R-shlib \
  --enable-memory-profiling \
  --with-blas \
  --with-lapack

make
sudo make install
/opt/R/${R_VERSION}/bin/R --version

sudo ln -s -f /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s -f /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript


Managing R Packages

We recommend using the pak package to manage R packages. It provides more explicit reporting of dependences:

install.packages('pak')
pak::pak('tidyverse')