πŸ“‹ Getting Ready

Author

On this page, you will find information on how to set up your computer for this course.

1. Install the Programming Language

Windows logo Python

Python is a general-purpose programming language that is becoming increasingly popular in the social sciences. It is free and open-source and runs on Windows, Mac OS X, and Linux.

  1. Download Python from the Python Software Foundation

  2. IMPORTANT: Run the installer and make sure to check the box that says β€œAdd Python to PATH” before clicking on β€œInstall Now”.

Windows logo R

R is a versatile programming language, with a focus on statistical computing. It is a big part of academic research in the social sciences. R is free and open-source and runs on Windows, Mac OS X, and Linux.

  1. Download the R installer from the Comprehensive R Archive Network (CRAN)

    • Choose the appropriate installer for your operating system and computer architecture (32-bit or 64-bit).
    • If on Mac, you will need to know if you are using an Intel or Apple Silicon (M1) processor.
  2. Run the installer and follow the instructions.

  3. You will also need to install R Tools. Many of the packages we will be using in this course require R Tools to be installed.

    If you are on Windows:

    • Download the latest version of the software from the R Tools for Windows page.
    • Run the installer and follow the instructions.

    If you are on Mac:

    • First, install the Xcode Command Line Tools. Go to the R Tools for Mac page and follow the instructions. Note: the precise instructions will vary according to the version of macOS you are using.
    • Install the gfortran compiler, as also indicated on the R Tools for Mac page.

2. Install additional required packages

You will need more than just the programming language to work with data. You also need to install a lot of additional packages 1 to be able to do data analysis in Python or R.

Python logo Python

There are multiple ways to install Python packages. The approach we are going to use is to install miniconda, a free and open-source package manager that allows you to install, run, and update Python packages.

  1. Download miniconda from the miniconda installation webpage. Choose the appropriate installer for your operating system (Windows, Mac, Linux) and computer architecture (32-bit or 64-bit).

    • You can skip the (Optional) steps in the installation instructions for verifying the installation.

    Note: if you already have some experience with Python and have installed Anaconda, you can skip this step. Anaconda and miniconda are very similar, but Anaconda comes with a lot of additional packages that you probably don’t need and therefore uses more disk space. That is why we recommend using miniconda instead.

  2. VERY IMPORTANT: Run the installer and make sure to check the box that says β€œAdd Miniconda3 to my PATH environment variable”, despite the warning that it is not recommended. This will make it easier to use Python from the command line.

  3. Although not strictly necessary, it is a good idea to restart your computer after installing miniconda.

Windows logo R

There are several ways to install R packages. The most common way is to use the install.packages() function in R. Here is how you can install the tidyverse package, which is a collection of packages that are very useful for data analysis in R.

  1. On the R Terminal, type the following command and press Enter:

    install.packages("tidyverse")

    This will install the tidyverse package and all its dependencies.

    Note: It is very likely that you will get a message asking you to select a CRAN mirror. Choose the one that is closest to your location (London, UK).

    ⚠️ WARNING: It is very likely that you will get error messages saying that you need to install additional software before continuing. There is no way to antecipate what these messages will be because they depend on your computer’s configuration.

  2. Handle any errors that may arise. Here are some tips:

    • If you are on Mac, check if the errors include names that are related to the list of Mandatory Libraries listed on the R Tools for Mac page. If so, follow the instructions on that page to install the missing libraries.
    • Search the error message on Google. Type the error message and include the name of the package you are trying to install. You will likely find a solution on Stack Overflow.
    • Call me over if you have any questions or need help.

3. Install an IDE

The Terminal is a powerful tool, but it is not very user-friendly. To make your life easier, you should install an Integrated Development Environment (IDE) that provides a graphical user interface (GUI) to Python or R.

Python logo Python

In this course, we will adopt Python logo VS Code as our IDE.

Visual Studio Code (VS Code) is a very popular free and open-source IDE developed by Microsoft. It supports many programming languages, including Python, and comes with a lot of useful features, such as syntax highlighting, code completion, and debugging.

  1. Download Visual Studio Code from the VS Code website.

  2. Run the installer and follow the instructions.

  3. Install the Python extension for VS Code. This extension will provide you with many useful tools for Python programming, such as code completion, debugging, and linting.

    πŸ”— Link: Download the Python Extension for VS Code. Don’t forget to read the examples contained on that page to learn how to use the extension.

πŸ’‘ TIPS (Optional)

VS Code is very flexible. You can install many extensions to add new features to the IDE. For example:

  • Install the GitHub Copilot extension to get AI-powered suggestions as you write your code.
  • Install the Rainbow CSV extension to make it easier to read CSV files.
  • Install the JSON for VS Code extension to make it easier to read JSON files.
  • Install the XML Tools extension to make it easier to read XML (and HTML) files.
Windows logo R

In this course, we will adopt RStudio (RStudio) as our IDE for R.

RStudio is by far the most popular IDE used by R programmers. It is free and open-source and comes with a console and syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging, and workspace management.

  1. Download RStudio Desktop from the Posit website.

  2. Run the installer and follow the instructions.

Alternative: If you are already familiar with Visual Studio Code (VS Code), say because you have already used it for Python, you can also use it for R programming. You will need to do a bit of configuration to get it to work, though. If you choose to use VS Code, download and install the R Extension for Visual Studio Code and remember to follow the instructions on the Getting Started section of the extension page.

4. Working Directory

There are multiple ways to work with files in R or Python. We will follow a particular set of 'rituals' in this course to ensure that everyone is on the same page.

  1. Open the folder system on your computer. If on Mac, that would be Finder; if on Windows, that would be File Explorer.

  2. Create a folder named ME204 on your computer to store all the files you will create during this course.

  3. Inside this folder, create two subfolders: data and code.

    For example, if you are on Windows, this is how the folder structure should look:

  4. Set up the working directory 2 to the ME204 folder you just created, according to your IDE:

    VSCode logo (VS Code)

    1. Go to the File menu and click on Open Folder.

    2. Navigate to the ME204 folder you created and click on Open. If you get a prompt asking if you trust the authors of the folder, click on Yes (assuming you trust yourself).

    3. On the left-hand side of the window, you should see the ME204 folder and its contents.

    RStudio logo (RStudio)

    1. Go to the Session -> Set Working Directory -> Choose Directory....

    2. Navigate to the ME204 folder you created and click on Open.

    3. On the Files pane, you should see the ME204 folder and its contents.

    πŸ‘‰ Use the ME204/code folder to store all scripts for this course.

Footnotes

  1. πŸ“‘ Packages are collections of code that extend the functionality of the programming language.β†©οΈŽ

  2. A working directory is the folder on your computer where R/Python will look for files. This might seem like a minor detail, but understanding where your files are stored is crucial to make sure your code runs smoothly.β†©οΈŽ