Meet the toolkit

Published

January 7, 2025

In this course, we are going to use mainly R, RStudio, and Quarto to create and share documents.

Note that the objective of this course is not to teach you how to use these tools but to use them to learn about computational urban science. Follow the materials below to help you get up to speed with them.

What is R?

R is a programming language and software environment specifically designed for statistical computing and data visualization. It is widely used in data science, statistics, and academia for its rich ecosystem of packages and powerful data analysis capabilities.

Key Features of R:

  • Open-source and free to use.
  • Extensive library of packages for various statistical and data analysis tasks.
  • Strong community support.
  • Excellent data visualization capabilities.
  • Seamless integration with other programming languages like Python and C++.

Here’s a simple example of using R for basic arithmetic:

5 + 3 # Basic arithmetic in R
[1] 8

Main libraries to use in R:

  • Tidyverse: A collection of R packages designed for data science. It includes packages like ggplot2 for data visualization, dplyr for data manipulation, and tidyr for data tidying.
  • datatable: A package for fast data manipulation.
  • readr: A package for reading and writing data.
  • purrr: A package for functional programming.
  • caret: A package for machine learning.
  • tidymodels: A collection of packages for modeling and machine learning.

Tidyverse It is a great starting point for beginners as it provides a consistent and coherent data manipulation and visualization approach. It is based on tidy data and piping principles, making it easy to read and write code.

# Load the Tidyverse package
library(tidyverse)
mtcars |> 
  filter(cyl == 6) |>
  select(mpg, hp, wt)
                mpg  hp    wt
Mazda RX4      21.0 110 2.620
Mazda RX4 Wag  21.0 110 2.875
Hornet 4 Drive 21.4 110 3.215
Valiant        18.1 105 3.460
Merc 280       19.2 123 3.440
Merc 280C      17.8 123 3.440
Ferrari Dino   19.7 175 2.770

Resources to Learn R:

What is RStudio?

RStudio is an integrated development environment (IDE) for R that provides a user-friendly interface for writing, running, and debugging R code. It includes features like syntax highlighting, code completion, and integrated plotting tools to enhance the R programming experience.

RStudio IDE, image © Mine Çetinkaya-Rundel

Key Features of RStudio:

  • Script Editor: A text editor for writing R scripts.
  • Console: An interactive console for running R code.
  • Environment Pane: Displays information about the R environment, including variables and data objects.
  • Plots Pane: Displays plots and visualizations generated by R code.
  • Packages Pane: Manages R packages and libraries.
  • Help Pane: Provides access to R documentation and help files.
  • Viewer Pane: Displays HTML content generated by R code.

Resources to Learn RStudio:

What is Quarto?

Quarto is a document format that combines the power of R, Python, and Markdown to create interactive and reproducible documents. It allows you to embed code, visualizations, and interactive elements directly into your documents, making it easy to share and collaborate on data analysis projects.

All material in this course is made with R, RStudio, and Quarto, including the website, the lecture slides, and the labs.

Key Features of Quarto:

  • Supports multiple programming languages, including R, Python, Julia, and Observable.
  • Easy to integrate with RStudio and VSCode.
  • Can produce documents in HTML, PDF, Word, and other formats.

Here’s how you can use Quarto to create a report:

  • Install Quarto from Quarto.org.
  • Write your content in a .qmd file.
  • Render the file to your desired format (e.g., HTML).

Quarto document in RStudio, image © Mine Çetinkaya-Rundel

Here is a minimal Quarto document example

---
title: "My First Quarto Document"
author: "Your Name"
format: html
---

# Introduction
This is a simple Quarto document.

# A Simple R Code Chunk
Below is an example of an R code chunk:
```{r}
# A simple plot
x <- 1:10
y <- x^2
plot(x, y, main = "Simple Plot")
```

which will be rendered like

your-image-description

Resources to Learn Quarto: