Setting Up R
Introduction
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:
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:
options(
repos = c(default = "https://cloud.r-project.org/") # or "https://mirrors.tuna.tsinghua.edu.cn/CRAN/", "https://mirrors.pku.edu.cn/CRAN/", "https://mirrors.sustech.edu.cn/CRAN/", etc.
)
if (interactive()) {
suppressMessages(require(devtools))
}R and package installation
To install base R and tidyverse, follow these instructions. Note that when install.packages() is run for the first time on a fresh system, R will ask whether to create a personal library; answer yes to continue. To install other frequently used packages, follow the steps below.
First, install system dependencies in shell:
# system dependencies
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 `plumber2`
sudo apt install libmbedtls-dev cmake # required by `nanonext`, which are dependencies of `mirai` and `btw`Then, install the following packages and relevant dependencies in R:
install.packages(
c(
"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", # technical writing
"DT", "gt", "gganimate", "ggwordcloud", "ggraph", # data visualization
"odbc", "DBI", "RPostgres", "RMariaDB", # database interface
"reticulate", # python interface
"httr2", "plumber2", # web programming
"shiny", "bslib", "htmltools", "fontawesome", "crosstalk", "shinydashboard", "bsicons", "thematic", # shiny-related
"ellmer", "btw", # AI
"data.table", "dtplyr", "slider", "caTools", "bitops", "remotes", "bundle", "writexl" # misc
)
)