Saturday, 15 April 2017

The Zombie's Guide to Installing R on Ubuntu

There is a how-to in this post, scroll down until the other bolded heading or ctrl-F for guide. If you're wondering what the rest of this blog is like, read the whole thing.

Paperweights : Misadventures in Consuming and "Computing"

Just after we moved house at the end of 2015 I decided that I should get another laptop. Not a new laptop but another laptop.

You see, the major issue with the laptop that I had at the time was that it was fairly big and heavy, i.e. impractical when I wanted (on those rare occasions) to bring it in with me to uni. (Incidentally, this was why my granfather had given me the laptop in the first place.) Thus, what was needed was something pretty small and lightweight. It would also need to have an hdmi port so we could use it to watch television (this was envisioned as the primary function).

Now, you might remember that I have taken a couple of marketing papers and one of the big things in marketing is the notion of involvement. Specifically, with high involvement purchasing* like what happens when buying a laptop is that you do some research. Basically this involves shopping around and trying to find the best product-as-solution to a perceived problem. The thing is that I am a very price conscious consumer and I had the terrible luck to start my search on the same day as a one-off sale. And like the dweebish consumer I am, the one-off sale convinced me into making a decision I should have deferred. I bought an HP Stream pre-loaded with Windows 10. (Apple was never in the running.) We got it a few days later.

These laptops are pretty small (11" or thereabouts) and come in bright colours. They also have next to no hard-drive space (like 28 GB) and are thus designed entirely for the Cloud. This stuff is all fine although I didn't really appreciate it until after I bought it. After all, what I wanted was something that I could use occasionally for uni work (i.e. just needed enough space for Word and R/RStudio) and which could use the internet to watch stuff. And so life was good, for a time. I even called the computer Light Blue, which I thought was hilarious. (And it was.)

After a few months or whatever I started getting memory warnings. Somehow there was less than a GB of space left? It didn't make any sense. But it turns out to be a pretty common issue. Whether or not I would have thought to check for known memory issues prior to my experiences with Light Blue is definitely a question to ask, but I feel like maybe I could have saved myself the memory trouble if I had started the search even a day later. Anyway, I found a solution... but I forget what it was.

Life went on and Light Blue was pretty much used exclusively to watch the great many different things we watch on things like TVNZ On Demand or play Youtube videos when we've been cooking. But then, after some months, I became aware that the memory was filling up again. And this time I couldn't find a way out of the fix. This was, I guess, when I resolved to install Ubuntu.

I've been aware of Linux generally and Ubuntu specifically for some years now. This is because on some of the websites I visit some of the other users are Ubuntu-ites and they talk about this in OS threads. However, I had never really met anyone who used Linux except this one dude who I don't know very well and who I haven't seen for over a year anyway. So, I decided to do some research about Christmas-time last year (I think I had finally decided to actually go ahead with my plan rather than having conceived it then). The results were clear. I needed to get two USB sticks and I should use them to install Ubuntu (as opposed to a different Linux system).

The idea was pretty simple. I would back up Light Blue as a Windows system on one of the data sticks and the other would be used to install Ubuntu. But I didn't do anything. That is, until today... the first weekend of the holidays and a few days after persistent crashes related to memory shortages. But it turned out that installing Ubuntu was the easy part (although I did have to do it twice, but this took like thirty minutes).

The truth is that I haven't changed what I need from a computer much in the last two years. Basically, LinuxBlue (I changed the name) needs to do exactly the same stuff as before. Luckily, Libre Office comes with Ubuntu and doesn't seem to have any major compatibility issues with Word (and if it does... copy and paste, am I right?). R doesn't come with Ubuntu as such, though. And installing it was a bit complex.

If you don't know what R is, you should find out. But basically, it's a statistical computing language (think like Python or Fortran but just for stats) based on S Plus, developed at the University of Auckland that is completely free. It represents the sum total of all my "coding" knowledge... and obviously I am a newbie when it comes to Ubuntu to Linux. Sadly, I think most people who want to use R on a Linux system aren't as end-usery as me... which meant it wasn't really clear how to get R onto the machine (RStudio was no problem, though). In fact, it was more troublesome than getting Ubuntu in the first place! Which brings me to the useful part of this blog:

A Beginner's Guide to Installing R on Ubuntu, by A Noob

Basically, we'll be following exactly what I did. So, start by following this link. All the stuff we'll be mindlessly typing was sourced from that helpful page.

The second thing is to go here and install RStudio. Don't try and open it because we haven't installed R yet so it won't work. Actually, you probably should try and open it (from "files") because that's what I did and this is a zombie's guide so we should probably follow the formula I used even if it is illogical. This is also your caution. Imagine that I am a moron. That's the level of expertise that went into the process you're about to follow (or read).

Next, go to the "search your computer" thing and find the terminal. Open it and type in, from the link:

sudo echo "deb xenial/" | sudo tee -a /etc/apt/sources.list
Now, you can probably change the url but, as I said, I'm a noob, so I wouldn't try when I can tell you for a fact that just mindlessly typing the stuff in works.

That being said, you need to type in your password at this point. If nothing shows up and you're randomly bashing keys, just press enter and then type your password and imagine that asterisks are popping up.  Then hit enter and mindlessly type the following:

 gpg --keyserver --recv-key E084DAB9

 gpg -a --export E084DAB9 | sudo apt-key add -

At this point I got a warning message. I ignored it.

sudo apt-get update
sudo apt-get install r-base r-base-dev

After the first one I got a bunch of prompts so just read those and always go with the yes option.

After the second one I wasn't sure if it had actually finished working or not, so I decided to open RStudio... which worked this time. I then installed s20x and R330 because they're packages I remember using from courses I have taken.

Hope this helps!

(And I am hopeful my decision to explore Ubuntu resolves the memory issue that looked as if it was creating a $300 paperweight.)

*See my recent blog post here for why this is a problematic concept . If you're wondering why it seems so much more pro than my usual stuff that's because it is actually just an essay I handed in last year that I couldn't be bothered copying from to explain involvement properly for readers of this post.

No comments:

Post a Comment