When it comes to using RStudio, doing so on the Linux operating system can be a bit of a pain (to put it mildly).
Essentially, certain libraries that would automatically be available in more mainstream operating systems such as Windows to operate with R are not so in Linux, and it is necessary to install these in order to yield the full benefits of R on a Linux operating system.
This article covers some of the issues that R users often face when trying to use the program on the Linux operating system, and how these can be remedied.
1. Install R on the Linux Terminal
Firstly, if we wish to run R through a console such as RStudio, we first need to install the R language within the Linux operating system itself using the Linux terminal. To do so, we open up our terminal (Ctrl+Alt+T) and input the following:
sudo apt-get update
sudo apt-get install r-base
In my case, we see that it’s already the newest version 🙂
Then, we can verify that the language is installed by opening up the terminal, and simply typing “R”:
2. Download RStudio
Now that we know the R language itself is installed, we then download the RStudio version compatible with Linux (Ubuntu 12.04/Debian 8+ at the time of writing):
3. Install the appropriate libraries and packages through the Linux terminal
Once the RStudio program has been installed in Linux, users will likely run into issues with installing the various libraries. Let us take an example of the quadprog package (which is a function in R dedicated to solving quadratic programming problems).
Let us suppose that we attempt to install and run the package in the usual manner (as one would in Windows):
install.packages(“quadprog”)
library(quadprog)
Upon attempting to install this package (or similar time-series related packages), we are greeted by a non-zero exit status error message:
Warning message:
In install.packages("quadprog") :
installation of package 'quadprog' had non-zero exit status
A non-zero exit status simply means that the command to install the library has failed to execute. The following Stack Overflow post also has more detail on this error.
In order to remedy this, we need to install what are called lib files. Essentially, lib files are the import libraries that allow Linux to connect to the appropriate R Server and download the specified packages. Therefore, we can install the curl and lib files in the Linux terminal as follows:
sudo apt-get install curl
sudo apt-get install libssl-dev
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libxml2-dev
However, note that the above commands only work for some libraries, not all – with the quadprog library as mentioned above being a notable exception.
Note that even upon installing the above files, attempting to run certain libraries will still result in an error due to the lblas and llapack packages still being missing, which are needed for certain libraries. These errors will persist even with the above installations.
In order to remedy this, we open up our terminal once again and install as follows:
sudo apt-get install liblapack-dev -y
sudo apt-get install liblapack3 -y
sudo apt-get install libopenblas-base -y
sudo apt-get install libopenblas-dev -y
Let us now try to install the quadprog library again within the RStudio console. We see that upon typing the install.packages(“quadprog”) and library(quadprog), the quadprog package has been installed and the library activated:
Conclusion
Ultimately, when it comes to using R within the Linux environment, many of the libraries and packages that would have come pre-installed with Windows are missing in Linux. Given that utilising R to its full potential (as with any major programming language) depends on downloading libraries through connecting and streaming such packages through the appropriate servers, configuring Linux as above is necessary to run important packages in R. Upon doing so, you should find that R for Linux has all of the capabilities of that seen in Windows, Mac, and cloud-based consoles.












