Installing R, RStudio and Git

First, although not necessary, we recommend you use Chrome as your browser. You can freely download and install Chrome here.

In this section we will describe how to install the software tools that we recommend as the main productivity tools for data science. To motivate the use of these tools, we will also provide brief illustrations of how we use them. We will install the following three software tools:

  1. R - The programming language we use to analyze data.
  2. RStudio - The integrated desktop environment we use to edit, organize and test our R scripts.
  3. Git - The version control system we use to keep track of changes made to our code and to sync local copies of our code with copies hosted on GitHub.
  4. Git Bash (for Windows users only) - A piece of software that emulates Unix on Windows machines.

We will also show how to open a GitHub account and sync it with RStudio.

Installing R

RStudio is an interactive desktop environment, but it is not R, nor does it include R when you download and install it. Therefore, to use RStudio, we first need to install R.

  1. You can download R from the Comprehensive R Archive Network (CRAN). Search for CRAN on your browser:

  1. Once on the CRAN page, select the version for your operating system: Linux, Mac OS X or Windows.

Here we show screenshots for Windows, but the process is similar for the other platforms. When they differ we will also show screenshots for Mac OS X.
  1. Once at the CRAN download page, you will have several choices. You want to install the base subdirectory. This installs the basic packages you need to get started. We will later learn how to install other needed packages from within R, rather than this webpage.

  1. Click on the link to the latest version to start the download.

  1. If you are using Chrome, at the bottom of your browser you should see a tab that shows you the progress of the download. Once the installer file downloads, you can go ahead and click on that tab to start the installation process. Other browsers may be different so you will have to find where they store downloaded files and click on them to get the process started.

    If using Safari on a Mac, you can access the download here:

  1. Now you can now click through different choices to finish the installation. We recommend you select the all the default choices.

    Even when you get a omnimous warning

    When selecting the language, consider that it will be easier to follow this book if you select English.

    Continue to select all the defaults:

    On the Mac it looks different, but you are also accepting the defaults:

Congratulations! You have installed R.

Running R

Although we highly recommend that beginners use R through RStudio, you can use R without RStudio.

You can start it like any other program.

If you followed the default installation, on Windows a shortcut will appear on your desktop which you can click to start R.

On the Mac, R will be in the Application folder.

If you start R without RStudio, you will see an R console in which you can start typing commands:

But we will be much more productive using an editor developed for coding, such as the one provided by RStudio. In the next section, we demonstrate how to install RStudio.

Installing RStudio

  1. You can start by searching for RStudio on your browser:

  1. You should find the RStudio website this way. Once there, click on Download RStudio.

  1. This will give you several options. For what we do in this book, it is more than enough to use the free Desktop version:

  1. Once you select this option, it will take you to a page in which the operating systems options are provide. Click the link showing your operating system.

  1. Once the installation file is downloaded, click on the downloaded file to start the installation process:

  1. We recommend clicking yes on all the defaults.

On the Mac, there are fewer clicks. You basically drag and drop the RStudio Icon into the Applications folder icon here:

Congratulations! You have installed RStudio. You can now get started as you do on any other program in your computer.

On windows you can open RStudio from the Start menu. If RStudio does not show, you can search for it:

On the Mac, it will be in the Applications folder:

Pro tip for the Mac: To avoid using the mouse to open RStudio, hit command+spacebar to open Spotlight Search and type RStudio into that search bar, then hit enter.

Installing Git

Another great advantage of RStudio projects is that one can share them with collaborators or the public through GitHub. To do this, we will need a piece of software named Git as well as access to a Unix terminal.

The installation process for Git is quite different for Mac and Windows. We include both below.

Git is what we refer to as a version control system. These are useful for tracking changes to files as well as coordinating the editing of code by multiple collaborators. We will later learn how to use GitHub which is a hosting system for code. You need Git to interact with GitHub. Having your code and, more generally, data science projects on GitHub is, among other things, a way to show employers what you can do.

Git is most effectively used with Unix, although one can also use it through RStudio. In the next section, we describe Unix in more detail. Here we show you how to install software that permits you to use Git and Unix. The installation process is quite different for Windows and Mac, so we include two different sections.

Installing Git and Git Bash on Windows

Warning: These instructions are not for Mac users

There are several pieces of software that will permit you to perform Unix commands on Windows. We will be using Git Bash as it interfaces with RStudio and it is automatically installed when we install Git for Windows.

  1. Start by searching for Git for windows on your browser and clicking on the link from git-scm.com.

  2. This will take you to the Download Git page from which you can download the more recent maintained build:

  1. You can then accept to run the installer and agree to the license:

  1. In one of the installation steps you will be asked to pick the default editor for Git. Unless you are already a vi or vim user, here we recommend against selecting vim which might be the default. If you do not recognize an editor you are familiar with among the options given, we recommend that you select nano as your default editor for Git since it is the easiest to learn:

  1. The next installation decision is actually an important one. This installation process installs Git Bash. We recommend that you select Git and optional Unix tools from the Windows Command prompt as this will permit you to learn Unix from within RStudio. However, if you do this, some commands that run on your Windows command line will stop working. If you do not use your windows command line, then this should not be a problem. Also, most, if not all, of these Windows command lines have a Unix equivalent that you will be able to use now.

  1. You can now continue selecting the default options.

    You have now installed Git on Windows.

  2. A final and important step is to change a preference in RStudio so that Git Batch becomes the default Unix shell in RStudio:

  1. To check that you in fact are using Git Bash in RStudio, you can open a New Terminal in RStudio:

  2. It should look something like this:

Installing Git on the Mac

Before we show you the installation process we introduce you to the Terminal. Macs already come with this terminal and it can be used to learn Unix. We can also use it to check if Git is already installed and, if not, start the installation process.

  1. To open a terminal, you can use command+spacebar and type terminal or you can find it in utilities:

  1. Once you start the terminal, you will see a console like this:

  1. You might have Git installed already. One way to check is by asking for the version by typing:

    git --version

    If you get a version number back, it is already installed. If not, you will get the following message:

    and you will be asked if you want to install it. You should click Install:

  1. This will take you through the installation process:

  1. Once installed, you can check for the version again and it should show you something like this:

Congratulations. You have installed Git on your Mac.

Reminder: On Windows, we install Git Bash. We do not need to do this on the Mac since they come with the terminal pre-installed and we can use this to run Unix commands.