Sunday, December 3, 2017

Installing Crouton and R-Studio on a Chromebook for Beginners Pt 3: R-Base and R-Studio

R-Base

Phew, OK so now you're in your chroot and everything is all Linux-y. This will probably offend someone, but every time I'm in a Linux environment like this one, it makes me think of my grandparents' ancient Mac that we could barely use to check e-mail and was really only good for playing Spin Doctor. There are certainly other styles around, but the xfce desktop has the classic Linux look and I do like it. 

Our ultimate goal, running R-Studio, is within reach now. When I was using a different Ubuntu setup (Lucid Lynx) on a PC in my undergrad, this step required no code and felt like downloading an app for your Mac or Windows computer. I think R-Base actually came already installed and installing R-Studio was as easy as searching for it in the Ubuntu "store" equivalent and clicking the install button. As far as I could find, no such option was available in the chroot. So we get more coding practice instead!

The first step is to open your terminal, which you should see on your dashboard at the bottom of your screen. Unlike opening the crosh in your Chrome OS, we don't need to give the shell command here in order to access the computer directly. My first step was to install git with the command
sudo apt-get install git
This will prompt you for your password (which you should have set the first time that you opened your chroot) because of the sudo command. I don't think that installing git is actually a pre-requisite to installing R and R-Studio, but as I understand it's generally good practice for anyone working with their Linux environment in a "developer" capacity. Basically, git creates a history of all of the coding that you've done, such that you can track the changes that you make. 

Breaking down that command line, you should recognize sudo as your key into the computer's root system. apt stands for Advanced Package Tool, which is a software interface that simplifies the retrieval and installation process for a certain type of package (Debian) on Linux platforms. The apt-get command tells your computer to use APT to find the following string. Install is pretty straightforward, which tells your computer what to do when it finds the following string. Other parameters that can be used in this place with the apt-get command include things like update. And finally git is the name of the object that you are trying to access.

Now to install the actual r-base, which is the most basic software that you need to use the R programming language. If you were to open up your R-base after installation you can perform all of the same tasks that we can do in R-studio, but it requires a lot more knowledge of code and doesn't have any shortcuts pre-installed. It actually runs inside the terminal, which is not at all intuitive for most of us who are used to using Windows or Mac interfaces. This is why many people have moved to using R-studio, which makes programming in R much more user-friendly.

In order to start the r-base installation, we need to give the computer the information it needs to access the r-base files with the command
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
Basically, this string is searching for and downloading the necessary "key" to authenticate the r-base files, since this is not included in the APT by default. The apt-key command tells your computer that you want to manage your APT keyring (which is full of authentication details for all of the APT packages). The string adv--recv-keys tells your computer that you are looking for a new key and the intervening string keyserver keyserver.ubuntu.com specifies where you want to look for it. E084DAB9 identifies the specific key you are looking for.

Next we use the string
sudo add-apt-repository ppa:marutter/rdev
to tell the computer where to look for updates for r-base in the future, since this also does not come as a default in APT. add-apt-repository does exactly what it says and adds a repository to the APT. In this case, the repository ppa:marutter/rdev is a place where the developer of R-base ( Michael Rutter) can put updates and other relevant information to keep the package running smoothly.

I didn't run into this problem, but apparently a lot of people run into the error
sudo: add-apt-repository: command not found
in which case you can install the necessary commands using
sudo apt-get install software-properties-common
Am I the only one excited that we know what that whole string does?!? The only thing we don't necessarily know is software-properties-common, which is a package that allows you to manage the most common types of repositories.

Now we are finally ready to install R-base using these strings
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install r-base
This should also look pretty familiar! Since we just added a new repository with new information, we first need to update and upgrade our APT. Now the APT should include R-base and all of the information that we need to install and authenticate it. So we install it. Woot woot! If you are feeling curious, go ahead and open it up to see the fruits of your labor using
sudo R start
It's not very interesting to look at, but I always find it satisfying to see exactly what I've been working toward.

R-Studio

And this is it! We're finally doing the thing we wanted to do in the first place!

We start with
sudo apt-get install gdebi-core
The gdebi-core package is very similar to APT in that it allows you to install Debian packages. However, APT accesses its packages via ftp or http, whereas gdebi accesses its packages locally on your computer.

Next, we need to actually download the r-studio package onto our computer using
wget https://download1.rstudio.org/rstudio-1.0.44-amd64.deb
As you might have guessed from this string, the R-studio package is found online at the above address. wget stands for web-get, and is used to download files over a network.

Once the download is complete, we then use gdebi to install the package
sudo gdebi rstudio-1.0.44-amd64.deb
You'll notice here that we don't have to specify what we want gdebi to do with the file that we downloaded like you do when using APT. Since the packages that gdebi accesses are locally stored, it's usually safe to assume that they will not be ever-changing with updates like a package that's accessed over ftp or http might be. In this way, having different parameters for install, update, or upgrade are not useful in gdebi, so the default command for gdebi is to install the following package.

And that should be it! To run R-studio you can find the icon in your list of apps, or use
sudo rstudio start
which should bring up the nice and comfortable interface of R-studio. 

In my case, when I tried to run r-studio this way nothing appeared to happen in the chroot at all, and when I looked back at my crosh (which it took me awhile to do) I found the message
rstudio: error while loading shared libraries: libxslt.so.1: cannot open shared object file: No such file or directory
This file, libxslt.so.1, is apparently necessary for some part of the r-studio function that is above my paygrade. It has something to do with the XSLT language that is used in the GNOME project, but that's about as deep as I could get before I got lost. Luckily, the solution to this problem is pretty straightforward
sudo apt-get install libxslt1-dev
We just have to install the package that R-studio wants to use! And there we go!

You now have transformed your chromebook from what it was designed for (basically internet-only) into a machine that is freer than even your average full PC or Mac. Congratulations and well-done :-)

No comments:

Post a Comment

English Syntax Trees and Question Creation with Flex and Bison

In the first (official) semester of my PhD program this spring, I was able to take a Computer Science class called NLP Methods in which we m...