Skip to content

Instantly share code, notes, and snippets.

View Lextuga007's full-sized avatar
:octocat:

Zoë Turner Lextuga007

:octocat:
View GitHub Profile
@francisbarton
francisbarton / imd_api.R
Last active June 13, 2025 14:31
Pull England 2019 IMD data from ONS API
# https://gist.github.com/francisbarton/5d9d177978a2279cf225abdc772adef9
ons_api_base <- "https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest"
imd_dataset <- "Index_of_Multiple_Deprivation_Dec_2019_Lookup_in_England_2022"
req <- httr2::request(ons_api_base) |>
httr2::req_url_path_append("services") |>
httr2::req_url_path_append(imd_dataset) |>
httr2::req_url_path_append("FeatureServer/0/query") |>
httr2::req_url_query(f = "json")
@tomjemmett
tomjemmett / bipartite_matching_with_jaccard_similarity.qmd
Last active May 29, 2024 15:34
Fuzzy joining tables using string distance methods
---
title: "Fuzzy joining tables using string distance methods"
format: html
---
```{r setup}
suppressPackageStartupMessages({
library(tidyverse)
library(sf)
library(janitor)
@xenatisch
xenatisch / to_decimal.r
Created January 5, 2023 12:40
Convert non-decimal integer numbers as string to decimal integers in R
# Examples:
# to_decimal("83", 12) : 44
# to_decimal("01101", 2) : 22
to_decimal <- function(num, base) {
digits <- strsplit(num, "")[[1]]
value <- 0
sequence <- seq_along(digits)
@AlbertRapp
AlbertRapp / nycflights_calender.qmd
Created July 9, 2022 11:15
NYC flights calendar plot
library(tidyverse)
color_palette <- thematic::okabe_ito(8)
flights <- nycflights13::flights
counts <- flights %>%
mutate(
date = lubridate::make_date(year = year, month = month, day = day)
) %>%
count(date) %>%
mutate(
@tomjemmett
tomjemmett / reinstall_steps.md
Last active May 3, 2023 15:43
reinstall r packages after an upgrade

Reinstall R packages after an upgrade

Packages that you install in R are tied to a particular version of R, so after installing a new version none of your previously installed pacakges will remain. I tend to think of this as a feature (time for a spring clean...), and then just reinstall pacakges that I know I need (e.g. install.packages(c("tidyverse", "usethis", "devtools"))) and continue to install pacakges as I realise that I need them.

However, if you really want to reinstall the previous set of packages, the steps below will help. First, we collect a list of packages that were installed from CRAN and a list of packages that were installed from GitHub repositories. Once we have those lists, after intalling the new version of R we can load the list of those packages and reinstall them.

@tomjemmett
tomjemmett / ccg_to_202122.R
Last active May 26, 2021 15:36
script and csv to get a list of ccg codes and what they are mapped to in 2021/22. all ccg's are present in the file, in the case of a ccg that has not changed since it's introduction old_code == new_code, allowing you to perform a join to another dataset without losing rows.
library(tidyverse)
ccgs <- NHSRtools::ods_get_ccgs() |>
select(name, org_id, last_change_date, status) |>
filter(str_detect(name, "^NHS .* CCG$"))
ccg_successors <- NHSRtools::ods_get_successors() |>
semi_join(ccgs, by = c("old_code" = "org_id")) |>
select(old_code, new_code)
library(tidyverse)
library(scales)
library(ambient)
heart_x <- function(angle) {
x <- (16 * sin(angle)^3)/17
return(x - mean(x))
}
@tomjemmett
tomjemmett / nhse_ae_tidy_csv.R
Last active November 14, 2020 14:12
Downloads and tidies the A&E stats from NHS England
library(tidyverse)
library(lubridate)
library(readxl)
library(httr)
library(rvest)
library(glue)
# We want to download all of the monthly excel files from Nhs England.
# These are all found from the following location
baseurl <- glue("https://www.england.nhs.uk/statistics/statistical-work-areas/",
@mattjbayly
mattjbayly / Replace_multiple_strings.R
Last active February 14, 2025 16:43
Replace multiple strings across multiple text files
#' Replace multiple strings across multiple files with original values and replacement values.
#'
#' files - A character string of file names to work through.
#' f - A character string of original values that you want to replace.
#' r - A character string of replacement values (f->r).
multi_replace <- function(files="", f="", r=""){
file_line = data.frame() # (optional) tracking table
#loop through each file separately
for(j in 1:length(files)){
nl <- suppressWarnings(readLines(files[j])) # read file line by line