The Ultimate Guide to Installing R and RStudio from Scratch

The following recipe is applicable to a machine (maybe a virtual one) running under Kubuntu 20.10 Desktop, but may be helpful for other Linux distros, too. In order to brush things up for Google: We are talking about ./configure, make, make install of R (r-project.org) and installing RStudio (rstudio.com) on a Linux computer.

One advice before you start working on your computer: Please, read this article completely before you begin hammering on your keyboard! It is of utmost importance, that you understand what you do and how you have to do it! Okay? Thank you!

This article is the result of at least two days of hard work, reading more than one hundred articles and error descriptions, searching for libraries, their applicable names for apt-get/apt install, and much more. You know that. But, let’s begin.

One warning: If you have installed Anaconda on your machine, remove it, and do it exactly like it is described by the Anaconda people! I have just tried to repair my installation of R on a second machine which had Anaconda on it, and the make run ended up with errors and there were path references pointing to my Anaconda installation. I’m more than just suspicious that there are only two ways to go: Either you go for native R or you go the Anaconda way. Then you can stop reading any further. Or you read until the end of the article and make a new decision.

When you install RStudio, there is no R environment or R language coming as a companion. You should install R first, and then RStudio on top. And here is how I dit it:

Installing R

First, download the tarball from https://www.r-project.org/.

In the following we use two commands which need two preliminary dashes you have to use, these may be hard to recognize depending on your display. DO NOT enter these two commands right way, this is just an announcement of things to come:

  1. apt --fix-broken install with two dashes before fix like so: --fix
  2. ./configure --enable-R-shlib with two dashes before enable like so: --enable
    
    And do not forget the preliminary ./ (dot slash) directly followed by configure!

Second, do these preparations (either with sudo in front of every single command or better, become root by sudo su) before beginning work on the tarball:

  1. apt-get install libclang-dev
  2. It is possible that you get a hint to use apt --fix-broken install. If so, do it!
  3. apt install gfortran
  4. apt install g++
  5. apt-get install libreadline6 libreadline6-dev
    
    (Read the PS about this command if it fails for you!)
  6. apt install libncurses-dev
  7. apt-get install xorg-dev
  8. apt-get install libbz2-dev
  9. apt-get install liblzma-dev
  10. apt install libpcre2-dev
  11. apt install libbiojava-java

Now we extract the tarball and enter the new R directory. Here we have to do the following:

  1. make clean
  2. ./configure --enable-R-shlib (Do note the leading ./ ! 
    And there are two dashes before enable!)
  3. make
  4. make install

Step 2. is most important! The option ‒‒enable-R-shlib (WordPress shows the two dashes possibly as one! Be careful!) is not documented, but RStudio will tell you about it if you installed without using it! In this case, it doesn’t find its shared library. And this is essential! And you cannot repair it by creating a symbolic link. That’s the wrong way to (pseudo-)resolve the problem.

Installing RStudio

Now download the RStudio package and install it:

dpkg -i rstudio-1.3.1093-amd64.deb

This is the one for standard PCs with 64 bit OS, take care to download the right one for your machine.

Run RStudio, it should start without a problem.

A little unsolved problem in RStudio [SOLVED, see PPS!]

In RStudio I encountered one minor problem though, regarding ggplot.

The command

p1 <- ggplot() + geom_line(aes(y=value, x=run), data = somedata) 
p1

throws this error:

Error in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) : 
X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at size 11 could not be loaded

I have tried to install additional fonts and lots and lots of other things, but to no avail.

There are numerous hints out there to resolve this but none of them worked for me. But at least I found out the following: There are different themes to choose from when using ggplot(), if you don’t see themes marked (ggthemes) you may install them by

install.packages("ggthemes")

or use the package menu to do so. You should see a list like this:

RStudio ggplot() themes

RStudio ggplot() themes

You activate them as follows:

p1 <- ggplot() + geom_line(aes(y=value, x=run), data = somedata) + theme_calc()

theme_calc() worked fine for me and showed this graph:

Graph w/ theme_calc()

Graph w/ theme_calc()

You may choose theme_void() as an alternative or a starter. It seems as if the default theme doesn’t work at all, but other themes do. If you find a way to repair this, let me know!

Good luck!


PS:

Installation of libreadline-stuff may fail with the error that no targets can be found. In this case, visit

https://www.ubuntuupdates.org/package/core/groovy/main/base/libreadline-dev

Here you can download a deb-package which can be installed using dpkg -i.

PPS:

I’m still working on the ggplot2 bug. At least I consider it a bug. The good news is that I’ve got in contact with one of the developers of RStudio, and I’m somewhat optimistic that we will be able to sort things out, stay tuned!

Update, 2021-01-07: And here we are: I have found a solution! It was not a bug, it was indeed a simple font missing, and I have discovered a website where you can download a suitable font legally and for free:

http://www.fontineed.com/font/Hu_Adobe_Garamond

Once you have installed this font correctly on your system, you can use all themes! I’m so happy about this, I can’t tell 😂😝😃😝😁 ☑

But, folks, the question remains: I have told the developer that from my point of view it is not the best of all ideas to hardcode a fontname in the source code! And this is especially true for software which is supposed to run on quite a number of different OS platforms. The only system I know which has pre-installed Adobe fonts was SUN Solaris in the good days of old. It’s quite typical for people coming from this platform to code things like this.

And I think it is an excellent idea to remove this codepiece from RStudio. Just my two dollars 😬 !