Setting Up R

hacking skills






Guidance on setting up a fresh R installation.


This is one of a series of posts where I document software configurations for personal reference. This post documents the configurations for R.

Notes on R’s startup process

There’s a good post from rstudio that explains R’s startup process. Figure 1 from that post is especially relevant to the current post since it explains how R looks for various kinds of configuration files:

Figure 1: R startup process

This post will concentrate on user- or project-specific files, so all the files mentioned below should be placed in a user’s home directory or in the working directory of a project.

Basic setups

Edit ~/.bashrc and create an alias for R with some useful startup options:

alias R='R --no-save --no-restore-data'

Edit ~/.Rprofile and add the following content:

  repos = c(default = "") # or "", "", "", etc.

if (interactive()) {

R and package installation

To install base R and tidyverse, follow these instructions. To install other frequently used packages, follow the steps below.

First, install system dependencies in shell:

# system dependencies
wget -O ./quarto.deb<version>/quarto-<version>-linux-amd64.deb && sudo apt install ./quarto.deb # required by `quarto`; substitute `<version>` for a specific version number
sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev # required by tidyverse
sudo apt install xclip wl-clipboard # required by RStudio addin `clipr` (choose`xclip` for x11, or `wl-clipboard` for wayland)
sudo apt install unixodbc-dev # required by `odbc`
sudo apt install libpq-dev # required by `RPostgres`
sudo apt install libmariadb-dev # required by `RMariaDB`
sudo apt install libv8-dev # required by `V8`, which is a dependency of `embed`
sudo apt install libgsl-dev # required by `RcppGSL`, which is a dependency of `tidyclust`
sudo apt install libsodium-dev # required by plumber

Then, install the following packages and relevant dependencies in R:

    "tidyverse", "tidymodels", "devtools", # meta-package
    "randomForest", "xgboost", "lightgbm", "bonsai", # supervised learning: tree-based
    "torch", "luz", "brulee", "tabnet", # supervised learning: deep learning
    "tsibble", "fable", "feasts", "fabletools", # supervised learning: time series
    "censored", "tidyclust", # unsupervised learning
    "embed", "themis", "textrecipes", "stacks", "probably", # machine learning: pre/post-processing
    "earth", "e1071", # machine learning: other
    "corrr", # statistics
    "quarto", "tinytex", # technical writing
    "DT", "gt", "gganimate", "ggwordcloud", "ggraph", # data visualization
    "odbc", "DBI", "RPostgres", "RMariaDB", # database interface
    "miniUI", "datapasta", "markdown", # RStudio addins
    "reticulate", # python interface
    "httr2", "plumber", "shiny", # web programming
    "data.table", "dtplyr", "slider", "caTools", "bitops", "remotes", "bundle" # misc


tinytex::install_tinytex(repository = "", bundle = "TinyTeX") # restart RStudio if this command is executed in it
# alternatively, download a tinytex release from and then execute:
# tinytex:::install_prebuilt('./TinyTeX.tar.gz') # restart RStudio if this command is executed in it


File templates

See this post.

RStudio setups

Tools -> Global Options -> General:

  1. Uncheck “Restore .RData into workspace at startup”.
  2. Set “Save workspace to .RData on exit” to “Never”.
  3. Uncheck “Always save history (even when not saving .RData)”.

Tools -> Global Options -> Code -> Editing:

  1. Check “Use native pipe operator, |> (requires R 4.1+)”.
  2. Check “Soft-wrap R source files”.

Tools -> Global Options -> Appearance:

  1. Editor font: “Ubuntu Mono”.
  2. Editor font size: 12.
  3. Editor theme: “Solarized Light”.

Tools -> Global Options -> R Markdown:

  1. Uncheck “Show output inline for all R Markdown documents”

Tools -> Modify Keyboard Shortcuts:

  1. Redo -> ctrl+y (by default, this shortcut is occupied by ‘paste last yank’).
  2. Reindent Selection -> ctrl+shift+i.
  3. Reformat Current Selection -> ctrl+shift+f (by default, this shortcut is occupied by ‘find in files’).
  4. Show Help for Current Function -> ctrl + e.