A clever bash script for R Users

[This article was first published on R | msperlin, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:
./UBUNTU_Install-Bash.sh
  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.

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

To leave a comment for the author, please follow the link and comment on their blog: R | msperlin.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)