Setting Up R

Forewords

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

See my previous post for instructions on how to install R and some packages.

A few 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 relavant 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 Environment variables

Edit ~/.Renviron and append the file with the following line:

LANGUAGE=en
LC_ALL=en_US.utf8

R Profile

Edit ~/.Rprofile and append the file with the following lines:

options(
  repos = ("https://cloud.r-project.org/") # or "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"
)

Edit the .Rprofile file in the working directory of a blog project created with blogdown and append the file with the following lines:

options(
  blogdown.author = "zenggyu",
  blogdown.ext = ".Rmd",
  servr.daemon = TRUE
)

RStudio

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 -> 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.

Some useful startup options

Edit ~/.bashrc and append the file with the following lines:

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

Install packages

# system dependencies
sudo apt install unixodbc-dev # required by `odbc`
sudo apt install libpq-dev # required by `RPostgres`
sudo apt install libmariadbclient-dev # required by `RMariaDB`
sudo apt install libv8-dev # required by `V8`, which is a recursive dependency of `embed`
install.packages(c("tidyverse", "tidymodels", # meta packages
                   "bookdown", "blogdown", "pagedown", "xaringan", # rmarkdown related
                   "xgboost", "lightgbm", "randomForest", "earth", "e1071", "embed", "themis", # machine learning
                   "tsibble", "fable", "feasts", "fabletools", # time series
                   "DT", "gt", "gganimate", "ggwordcloud", "plotly", # data visualization
                   "odbc", "DBI", "RPostgres", "RMariaDB", # database related
                   "datapasta", # RStudio addons
                   "reticulate", # python interface
                   "data.table", "dtplyr", "slider", "arrow", "sparklyr", "caTools", "bitops", "remotes", "DescTools")) # misc
blogdown::install_hugo()

Related

Next
Previous
comments powered by Disqus