Introduction to R - Installation

Recently, I introduced a new series here at overdetermined.net called "Introduction to R". Today I am going to, literally, introduce you to R and how to get it installed on your system. Later in the week I will discuss various ways of interacting with R that will be suitable for the exercises in this tutorial.

I am sure that many of you are familiar with tools like SPSS, SAS or Stata. R provides a more extensive suite of tools than any of these proprietary tools and costs nothing. As an open-source project, it is available to you (and everyone else), for free. As an end user, you are empowered to use and redistribute R, examine the source code, and make any changes or improvements you deem necessary. For a full historical description of the R Project, please refer to the R Project website or Wikipedia. For our purposes, R is an integrated set of tools designed to let you manipulate your data, perform calculations, and display the results. The R-Project's tools include:

    * Data handling and storage facilities,
    * A set of operators for calculations,
    * An integrated set of tools for data analysis,
    * A set of tools for producing tables and graphs either in print or on the Internet, and
    * A simple and effective programming language.
   
Unlike tools such as SPSS, the R Project does not provide a graphical user interface (GUI). Thus, R can seem intimidating to users who are not used to working in a programming environment. Although the learning curve is a little steep, the pay-off is worthwhile. R is far more powerful than the proprietary tools you may have used previously. In fact, R is so powerful that recent versions of SPSS have an optional plugin to extend SPSS' limited programmability via R. And advanced SPSS users know that even a good graphical interface is often limited. Most SPSS users are eventually forced to learn at least a little "SPSS Syntax". The R Project may be a little more direct, but the end results are remarkably similar.

Now, let's get R installed on your computer so I can go eat some lunch.

Installation - Notes
Earlier this year HummuSoft wrote a nice introduction to Ubuntu Linux. This article may have been your first introduction to Linux. Ubuntu is a Linux "distribution" (aka distro). Unlike Windows or Mac OS X, there are many versions of Linux. Distros such as Ubuntu, Fedora and SUSE provide an easy-to-use operating system that rivals anything produced by Microsoft or Apple. They are well-designed, powerful systems. Other distributions, such as Slackware and Gentoo, provide advanced tools for computer experts. What these distributions lack in ease of use, they make up for in flexibility, simplicity and power. All of these distributions are based on the same core tools and utilities and are relatively similar. However, installing software on each of these platforms is unique. I (pluribus) use Ubuntu Linux. Although I do intend to discuss my reasons for choosing this distro in greater detail, for the moment I would simply encourage you to read the this, which tells you a little about what makes Ubuntu such a great system. Whenever I describe how to do something on "Linux" you can assume my instructions will work on Ubuntu (or Debian). In some cases, users of other distributions may have to adapt my instructions to fit their environment. If any of you need help with a particular distribution, please let me know and I will try to write up a guide specifically targeted to your distribution.

Installation - Linux
Installing R on a Ubuntu machine is incredibly easy. In fact, it is much easier than installing R onto Windows. First, I will describe how to install R using the graphical tools that come with Ubuntu. Then I will describe how to install R using the command line tools. Either way, you will get the EXACT same end result.

Graphical - Look at the top, left hand corner of your screen. You should see three menu choices. From left to right these are: "Applications", "Places", and "System". Select "System". Go to the menu entry labeled "Administration" and select the "Synaptic Package Manager". You will be asked to enter your password. Once you authorize the package manager to continue, you will be presented with a tool that looks like this:

Synaptic

This tool (Synaptic) gives you access to thousands of programs. Modern Linux distributions handle program installation in a secure, centralized manner. You do not have to download programs from nameless Internet sites, hoping they work. On a Ubuntu system, the Synaptic Package Manager make software installation quick and easy.

Use the "Quick search" bar to find a package named 'r-recommended'. 

quick search

 

 

Right click on the r-recommended package and select "Mark for Installation". After you have done this, simply press the Apply button on the main tool bar. Agree with the dialog box that shows you that you are about to install all sorts of stuff onto your computer, and go get yourself a Diet Coke. In a little less than 5 minutes, your computer will be done.

Command-Line - R is a computer programming language. In the coming couple of months, you and I are going to spend many hours discussing the intricacies of commands and syntax. If you are the over-eager type, I promise that installing R from the command line is even easier than using the graphical tools. First, we need to open a terminal. Today, we will use the gnome-terminal. This is a little bit like the cmd.exe on Microsoft Windows, but it is much, much more powerful. You can start gnome-terminal in one of two ways.

#1 - Press Alt-F2 and type in the word, 'gnome-terminal'. Press enter.
#2 - Go to the top, left-hand corner of your screen. Click on Applications -> Accessories -> Terminal. When you are done, you should see something that looks a little like this:

gnome-terminal

I am not using the default system theme, so my gnome-terminal will look a little different from the one you may be looking at, but that is OK. Now all you have to do is type in the magical incantation:

sudo apt-get install r-recommended

Hit enter. You will be asked for your password. After that it will ask for authorization to install all sorts of stuff onto your computer. Grant it permission to do so, and go get yourself a Diet Coke. This will take a couple of minutes.

Installation - Windows/Mac
This is a little more involved than installation on a Linux machine. First, you will need to go to the R Project's website. On the left hand side, you will see a menu entry for CRAN. From there you will need to select a FTP mirror site that is in your country: the United States is at the bottom. For right now you will need to install the base system.
Windows - You are looking for a file called 'R-2.8.0-win32.exe'.
Mac - You are looking for a file called 'R-2.8.0-win32.dmg'.

Once you have downloaded this file, you will need to run the installation program. I assume Windows and Mac users know how to install programs using these files. If you have any problems, post a comment below this article and I will work with you to get it installed.

As we progress, Windows and Mac users may need to install additional components onto this core system. When this becomes necessary, I will walk you through doing this.

Starting R
Starting R is pretty easy. On Windows, you should find it in your applications menu. On Linux, you will need to start up a terminal (gnome-terminal) and type in R. Gotcha Warning - R and r are not the same thing. Linux is case-sensitive.

To end your R Session in Windows or Macs, you can leave R in the same way you would with any other program. On Linux you will need to either close gnome-terminal, which is just like closing a program on Windows OR you will need to issue the command q(). Coincidentally, q() works on Windows and Macs too.

Closing Comments
I know this was a long post. I will try to keep future posts a little more focused. If you have questions, comments, or just want to say hi, leave us a note. I promise, we don't bite. If you are chomping at the bit to get started I would recommend downloading An Introduction to R, which I still use regularly. Or, once you have started R, try the command demo().

Until Next Time,

--pluribus

 

 

long term care insurance