A clever bash script for R Users

Installing software and R packages easily

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

  1. Download the github repository as a zip file
  2. Unpack the zip file and check all .txt files in all sub-folders. Remove or add software/R packages as needed.
  3. Within a terminal, execute the main script:
  1. type your sudo password and wait…

Installed Software

The bash script includes the following software:

Using apt

  • libreoffice (lastest)
  • texstudio (latest)
  • obstudio (latest)
  • many others (see file apt-to-install/list_to_install.txt)

Using custom bash scripts

  • R (latest)
  • R Packages
    • See file R-pkgs/pkgs_to_install.txt
  • RStudio (latest
    • RStudio configuration – color scheme, size font, .. (see file Rstudio-Config/my-rstudio-prefs.json). You can get your own Rstudio preference file locally at ~/.config/rstudio/rstudio-pref.json.
  • Google Chrome (latest)

Using 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 renv::dependencies.


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() %>%

Marcelo S. Perlin
Marcelo S. Perlin
Associate Professor

My research interests include data analysis, finance and cientometrics.

comments powered by Disqus