Back in 2017 I wrote a blog post describing a simple bash script for installing R in a Ubuntu setup. The problem with this script, and many others found in the internet, is that they quickly become obsolete due to changes in Ubuntu, R and RStudio. For example, if Ubuntu version changes from “trusty” to “focal”, the link to the CRAN ppa also changes. The same is true with RStudio, which does not provide installation by apt, only downloadable .deb files from its website.
Today I manage to develop a clever bash script that uses the internet and local files to find out the current version of all software. Using three different methods – apt, snap and custom bash scripts – the script installs all required software in its latest version. The script also installs R packages set in a .txt file and configures RStudio to a dark theme. The best part is that all code is modular and you can easily customize your installs by changing .txt files in each sub-folder.
You can find the bash script in https://github.com/msperlin/UBUNTU-Fresh-Install.
How to use it
- Download the github repository as a zip file
- Unpack the zip file and check all .txt files in all sub-folders. Remove or add software/R packages as needed.
- Within a terminal, execute the main script:
- type your sudo password and wait…
The bash script includes the following software:
Using custom bash scripts
- Microsoft code (latest by snap)
Generating R package list
You can generate your own list of used R packages based on your existing code. For that, use the R code below, which will scan your files and retrieve all calls to existing packages. Do notice you’ll need to change the base folder in
library(dplyr) my_r_dir <- 'YOUR-FOLDER-HERE' df <- renv::dependencies(my_r_dir) n_to_colect <- 50 # number of pkgs to collect (most to least frequent) tbl_pkgs <- df %>% group_by(Package) %>% count() %>% arrange(-n) %>% #view() %>% ungroup() %>% slice(1:n_to_colect) tbl_pkgs