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(
  defaultPackages = c(getOption("defaultPackages"),
                      "tidyverse"),
  tibble.print_max = 500,
  tibble.print_min = 50,
  tibble.width = 150
)

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

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

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'

If a pre-loaded package (e.g., tidyverse) needs to be updated, run R in terminal with:

R --vanilla

Install packages

install.packages(c("tidyverse", "tidymodels", # meta packages
                   "bookdown", "blogdown", "pagedown", "xaringan", # rmarkdown related
                   "randomForest", "earth", "e1071", # machine learning
                   "tsibble", "fabble", "feasts", # time series
                   "DT", "gt", "gganimate", "ggrepel", "ggwordcloud", "GGally", # data visualization
                   "odbc", "DBI", # database related
                   "datapasta", # RStudio addons
                   "caTools", "bitops", "remotes", "DescTools")) # misc
blogdown::install_hugo()

Related

Next
Previous
comments powered by Disqus