R for Linux on Windows
As much as we try to make it so at Cape RADD, marine science isn’t all glamour and glitz! And that’s not to say we don’t make a huge effort to teach the less glamorous aspects like R and QGIS (and make them fun!). But it’s because at some stage, every marine biologist is going to need statistics in their lives.
I like to think I’m the resident statistician here at Cape RADD (I would hope so, my PhD is in statistical ecology!). And for that reason I’m very particular about my computer setup. Running statistical software on Windows has long been troublesome. Oftentimes R dependencies just don’t play nicely together on windows.
So for some time I ran a dual-boot system, booting to Ubuntu when I wanted to work in R and other software, and booting to Windows when I needed Word and some other things (shout-out to LibreOffice!). I even managed to access my Windows partition as a Virtual Machine from Ubuntu for some time, but ended up abandoning this solution. What I really enjoyed though, was the compatibility of a Linux system while having access to mainstream Windows software. Switching between the two was just not working for me.
As it happened, I recently joined the 21st century and upgraded my ancient Latitude E6500 and figured with the added memory and processing power that a Virtual Machine setup might again be a reasonable solution.
And then I discovered the Windows Subsystem for Linux.
I opted out of the free Windows 10 upgrade when it first went around several years ago and boy was that wrong! My Dell Latitude 5491 arrived pre-loaded with Windows 10, and in looking for solutions to my user demands, I discovered that Microsoft must be reading my mind and developed the Windows Subsystem for Linux (WSL). Think of it as a Windows kernel upon which a Linux user space can function.
So how can you get it?
Start by typing “Windows Features” into the Windows search box. Activate the “Windows Subsystem for Linux” check box in the dialog window that follows. Once successful, navigate to the Microsoft store and install your favourite flavour of Linux. I’m a fan of Ubuntu.
Launch Ubuntu from the Start Menu, just like any other app. The first time you do, you will need to setup a username and password, these can be different from your Windows username and password.
Next, Install R with the following command
sudo apt-get install r-base
This will install an older version of R from Ubuntu’s repository. Alternatively you can add your favourite CRAN repository mirror to get the latest version.
Once R is installed, you’ll need to download RStudio. You can access your Windows filesystem on ubuntu at /mnt/ so I navigate to my RStudio download with the follwoing
Then install RStudio, with the following commands. Note at the time of writing I was unable to get the latest version of RStudio 1.2.1335 to work.
gpg --keyserver keys.gnupg.net --recv-keys 3F32EE77E331692F sudo dpkg -i rstudio-xenial-1.1.463-amd64.deb
Install any unmet dependencies with apt and –fix-broken if necessary.
WSL is designed primarily for development purposes and doesn’t natively support graphical programs, but we can work our way around this with an X server. I like VcXsrv. Head on over there and while it’s downloading, append your ~/.bashrc file in Ubuntu with the following.
This will export your display for the X server to pick up. Install VcXsrv and run it with the XLaunch program. I’ve found that disabling Native opengl prevents some errors on Ubuntu.
Run RStudio from Ubuntu with the following
Now, Try the same with QGIS!