π Getting Ready
On this page, you will find information on how to set up your computer for this course.
1. Install the Programming Language
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.
Download Python from the Python Software Foundation
IMPORTANT: Run the installer and make sure to check the box that says βAdd Python to PATHβ before clicking on βInstall Nowβ.
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.
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.
Run the installer and follow the instructions.
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
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.
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.
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.
Although not strictly necessary, it is a good idea to restart your computer after installing miniconda.
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.
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.
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
In this course, we will adopt 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.
Download Visual Studio Code from the VS Code website.
Run the installer and follow the instructions.
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.
R
In this course, we will adopt (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.
Download RStudio Desktop from the Posit website.
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.
Open the folder system on your computer. If on Mac, that would be Finder; if on Windows, that would be File Explorer.
Create a folder named
ME204
on your computer to store all the files you will create during this course.Inside this folder, create two subfolders:
data
andcode
.For example, if you are on Windows, this is how the folder structure should look:
Set up the working directory 2 to the
ME204
folder you just created, according to your IDE:(VS Code)
Go to the
File
menu and click onOpen Folder
.Navigate to the
ME204
folder you created and click onOpen
. If you get a prompt asking if you trust the authors of the folder, click onYes
(assuming you trust yourself).On the left-hand side of the window, you should see the
ME204
folder and its contents.
(RStudio)
Go to the
Session
->Set Working Directory
->Choose Directory...
.Navigate to the
ME204
folder you created and click onOpen
.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
π Packages are collections of code that extend the functionality of the programming language.β©οΈ
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.β©οΈ