Chapter 2 - Getting and Installing R

R, in addition to being tricky to Google, is an open-source and free software package. R can be downloaded easily, and runs on multiple platforms. It’s also simple and fast enough to run on an ordinary laptop. This means you can build models while you’re sitting on your patio enjoying a tasty beverage (which I highly recommend if possible).

The first thing that you’ll notice when you load R is that you start with a blank page. That’s it. Just a blank screen and a cursor that impatiently waits for you to tell it to do something. If you’re anything like me, this is the most terrifying part of computer programming. The number of possibilities is essentially limitless, and you are entirely responsible for everything.

The flipside of that is that R is an incredibly flexible tool that lets you do all kinds of stuff, which makes it perfect for building models that are similarly flexible and varied. Technically, there is no limit to the type of models you can build with R, as long as you know what you’re doing. R also has a number of built-in functions, as well as sets of predefined programs (called ‘packages’) that can be downloaded from the internet. You can also build your own functions to tell R to do custom things.

If you want to learn how to use R to its full potential, this guide won’t take you very far. Outside of building models and some specific statistical functions, my knowledge of R is pretty rudimentary. There are online courses in R programming, or you can learn the way I did by poring over helpfiles and using trial and error as your teachers. Or you can make friends with someone who knows R. Or you can do something else, I’m not your dad.

In the following sections, I am going to summarize the features of R that I use when building models: parameters, arrays, random functions, and loops. First, I am going to talk a bit about getting your hands on the software itself.

Getting your hands on R

I don’t recommend using the normal R user interface. It’s frustrating and limited. You can’t cursor scroll, copying/pasting is a nightmare, results and code occupy the same space – it’s a mess. Instead, I am going to point you in the direction of one of two (or both) of the following programs:

  • Tinn-R: This is a user interface that people who use programs like SAS or STATA should find appealing and intuitive. Write code, scroll through it, copy and paste, all with ease. Submit statements one at a time or as a batch, and the results are produced in the R environment. The biggest downside of Tinn-R is the challenge of getting it to link with the R environment – I usually just copy and paste the code I want. It’s inelegant, but it works.

  • RStudio: This is the best solution that I know of for the limitations of R. RStudio allows you to code in one part of the screen, submit code through a ‘run’ button and see results in another part, keep track of all of the objects you’ve created in a third part, and displays graphs in a fourth. It’s a handy all-in-one. It also has built-in wizards for importing data, which is very handy.

Both Tinn-R and RStudio are free to download.

Next Chapter >

< Previous Chapter

« Back to Start