Setting Up R


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. The following figure from that post is especially relevant to the current post since it explains how R looks for various kinds of configuration files:

Figure 1

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.

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 # 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 recursive dependency of `embed`
sudo apt install libsodium-dev # required by plumber

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

    "tidyverse", # tidyverse
    "tidymodels", "embed", "themis", "textrecipes", "censored", "bonsai", "stacks", "torch", "luz", "xgboost", "lightgbm", "randomForest", "earth", "e1071", "brulee", "tabnet", # machine learning
    "tsibble", "fable", "feasts", "fabletools", # time series
    "quarto", "tinytex", # publishing
    "gt", "gganimate", "ggwordcloud", "ggraph", # data visualization
    "odbc", "DBI", "RPostgres", "RMariaDB", # database related
    "miniUI", "datapasta", "markdown", # RStudio addins
    "reticulate", # python interface
    "data.table", "dtplyr", "slider", "httr2", "caTools", "bitops", "remotes", "plumber" # 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.

R setups

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

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

Edit ~/.Rprofile set the following options for R:

  repos = "" # or ""

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 -> General:

  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.


comments powered by Disqus