A Linux Live USB as a statistical programming dev environment | R-bloggers

A Linux Live USB as a statistical programming dev environment | R-bloggers

This blog post is divided in two parts: in the first part I’ll show you how to create a Linux Live USB with persistent storage that can be used as development environment, and in the second part I’ll show you the easiest way to set up RStudio and R in Ubuntu. Making your own, portable, development environment based on Ubuntu or Debian I’m currently teaching a course at the University of Luxembourg, which focuses on setting up reproducible analytical pipelines (if you’re interested, you can find the course notes here). The problem is that my work laptop runs Windows, and I didn’t want to teach on Windows since I make heavy use of the command line. Plus I don’t have admin rights on this machine, so installing what I needed would have been a pain. I also don’t have a personal laptop, so I use my wife’s laptop. However, the laptop is completely full of pictures of our kids, so I couldn’t install what I needed… This is when I thought about making a persistent live USB with Kubuntu on it (Kubuntu is a variant of Ubuntu with KDE as the desktop manager instead of Gnome) with all the software I needed (R, Quarto, RStudio basically). It works quite well, and was also quite easy to do. But what is a live USB anyways? A live USB is a full Linux installation on a USB stick, that you can use to test different Linux distributions or even to install said distribution on computers. The first step is to get a USB stick. Those are quite cheap nowadays, but you’ll need at least one with 8GB of space, and ideally USB 3 (you probably can’t find any USB 2 these days anyways). I’ve bought a 32GB one for 10€. Then, we need to install Ubuntu on it. I’ll be using Kubuntu 22.04, which is an LTS release. I would always recommend an LTS release for something like crafting a development environment. So if you’re reading this in the future, and there’s a new LTS (could be 24.04, 26.04, etc), you’d need to get that one. Creating a live USB is quite simple, but the issue if you create a live USB using the standard methods is that whatever you do on it once you’re logged in while get erased after rebooting. A persistent live USB, I’m sure you’ve guessed it, keeps your changes even after rebooting, which means that you basically end up with a portable development environment. Note however that only Ubuntu (and variants) or Debian can be used to create persistent live USBs. You can create persistent live USB from another Linux distro, Windows or macOS. If you’re already running Ubuntu on your pc, you might want to take a look at this page. You’ll need to install a tool called mkusb. If you’re not running Ubuntu, but find this tool in your distribution’s package manager, I guess you’re good to go as well. In my case, I’m running opensuse tumbleweed, and could not find this program in the opensuse’s repositories. So I’ve used this guide that shows how to achieve the same thing using a very simple to use shell script which you can get here called mkusb-minp. So in my case, I simply had to stick the USB stick in my computer, find out where it was mounted by running df in bash (in my case it was in /dev/sdd), download Kubuntu’s iso image and run the following in my terminal: sudo ./mkusb-minp -p kubuntu-22.04.1-desktop-amd64.iso /dev/sdX (/dev/sdX: replace the X by the right letter, for me it was /dev/sdd) If you’re using Windows, you can install Rufus to create a persistent live USB. It would seem that for macOS the process is a bit more involved, but I’ve found this blog post that explains the process. Once the process is finished, you can boot into your live USB key. For this, you might need to press delete or F2 when your computer starts booting to access the boot menu. You can then choose to boot from your USB device. Wait a bit and at some point you should see a prompt asking you if you want to try or install Ubuntu. Choose Try Ubuntu: And then wait some minutes. Yes booting takes some time because you’re loading an entire operating system from a USB stick (hence why it’s a good idea to go with a USB 3 stick). After some time you should see a new window: Once again, try Ubuntu, wait a bit, and that’s it you’re inside your dev environment! Setting up R and RStudio Now that you’re inside your dev environment, you actually need to start adding some tools. Let’s start by adding R. The easiest way that I found is to use the r2u project by Dirk Eddelbuettel. If you’re on Ubuntu 22.04, run this script, as explained in the tutorial. This will add the required repositories that will install binary versions of R packages in mere seconds. The script will also add a repository to install the most recent version of R, so once the script is done running, install R and the (or any other package) with the following command: sudo apt install --no-install-recommends r-base r-cran-tidyverse You can then install other packages from R using install.packages(

Images Powered by Shutterstock