Skip to content

Instantly share code, notes, and snippets.

@Torvaney
Created July 1, 2018 22:24
Show Gist options
  • Save Torvaney/9b4c5c0cd7e9eec7392e03da22f2bf19 to your computer and use it in GitHub Desktop.
Save Torvaney/9b4c5c0cd7e9eec7392e03da22f2bf19 to your computer and use it in GitHub Desktop.
WIP/my flight is delayed
---
title: "UK flights"
---
```{r}
library(tidyverse)
library(rvest)
```
```{r}
base_url <- "https://www.caa.co.uk/uploadedFiles/CAA/Content/Standard_Content/Data_and_analysis/Datasets/Punctuality_stats/{yyyy}/{yyyymm}_Full_Analysis_Arr_Dep.csv"
```
```{r}
build_url <- function(yyyy, yyyymm) {
str_glue(base_url, .envir = list(yyyy = yyyy, yyyymm = yyyymm))
}
delay_urls <-
crossing(
yyyy = 2015:2017,
mm = 1:12
) %>%
mutate(yyyymm = paste0(yyyy, str_pad(mm, 2, pad = "0")),
url = map2_chr(yyyy, yyyymm, build_url))
delay_summaries <-
map_dfr(delay_urls$url, read_csv)
head(delay_summaries)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment