Quarto example: show R code

Author

John Smith

Published

4 October 2026

# Load packages
pacman::p_load(here, httr2, tidyverse)

# Create the directory for the original downloaded data
dir.create(here("data", "raw"), recursive = TRUE, showWarnings = FALSE)

# Download the original data
request(
  "https://mpjashby.github.io/crimemappingdata/medellin_homicides.csv"
) |>
  req_perform(path = here("data", "raw", "medellin_homicides.csv"))
<httr2_response>
GET https://mpjashby.github.io/crimemappingdata/medellin_homicides.csv
Status: 200 OK
Content-Type: text/csv
Body: On disk '/Users/mattashby/Documents/Crime Mapping Book/data/raw/medellin_homicides.csv' (702486 bytes)
# Load data
medellin_homicides <- here("data", "raw", "medellin_homicides.csv") |>
  read_csv2() |>
  # Remove rows with missing coordinates
  drop_na(longitud, latitud)
ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
Rows: 9360 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr  (2): sexo, modalidad
dbl  (3): longitud, latitud, edad
dttm (1): fecha_hecho

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Count number of homicides in February 2019
homicide_count <- medellin_homicides |>
  filter(year(fecha_hecho) == 2019, month(fecha_hecho) == 2) |>
  nrow()

There were 50 homicides recorded in February 2019.