Skip to content

Instantly share code, notes, and snippets.

View francisbarton's full-sized avatar
🌱
Sowing seeds for 2024

Fran Barton francisbarton

🌱
Sowing seeds for 2024
View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-GB">
<info>
<title>Harvard - University of Gloucestershire</title>
<id>http://www.zotero.org/styles/harvard-university-of-gloucestershire</id>
<link href="http://www.zotero.org/styles/harvard-university-of-gloucestershire" rel="self"/>
<link href="http://www.zotero.org/styles/harvard-sheffield" rel="template"/>
<link href="http://ist.glos.ac.uk/referencing/harvard/" rel="documentation"/>
<author>
<name>Francis Barton</name>

Keybase proof

I hereby claim:

  • I am francisbarton on github.
  • I am fbarton (https://keybase.io/fbarton) on keybase.
  • I have a public key whose fingerprint is E4E9 8FEF C41D 27CB 0C85 8C69 6DC4 22A9 890E 62A8

To claim this, I am signing this object:

@francisbarton
francisbarton / making_life_hard.md
Last active February 4, 2020 12:20
Making life hard for myself by trying to use the ONS Open Geography API

My mission: to programmatically analyse and map postcode-level fixed connectivity data for Harrogate district

I thought this would be quite a quick job.

  1. I knew that I had the postcode-level data from Ofcom
  2. I knew that I had a script for looking up latitude and longitude from a postcode, using [Chris Bell's API][doogal-api]
  3. I was pretty sure that a list of postcodes in the district would be downloadable from the [ONS Open Geography Portal][opengeo-home]

The easiest thing to do would have been to work in Excel using manually downloaded data from websites. But I wanted to construct a script to retrieve, process and combine the data [programatically][] and [reproducibly][] and preferably [DRY][]-ly as well.

@francisbarton
francisbarton / map_mutate_problem_reprex.R
Last active February 11, 2020 04:21
trying to make map* work with mutate to make new df columns from a list
# load packages -----------------------------------------------------------
library(rlang)
library(dplyr)
library(tidyr)
library(magrittr)
library(purrr)
library(nomisr)
@francisbarton
francisbarton / map_mutate_solution.Rmd
Last active October 20, 2021 03:23
solution to my terrible mutate problem, via Eugene Chong on StackOverflow
I asked [a question on Stack Overflow][soq] about a super-annoying problem I was experiencing.
I created a [reprex][repr] for it and posted it [as a gist here][gist1] but in the end I did not need to point to the whle reprex: the slightly edited, shorter reprex I posted on the SO q was sufficient.
Within a matter of minutes the question had received a very accurate and helpful reply from [Eugene Chong][ec_up].
[soq]: https://stackoverflow.com/questions/60155799/how-can-i-use-map-and-mutate-to-convert-a-list-into-a-set-of-additional-columns
[repr]: https://reprex.tidyverse.org/articles/reprex-dos-and-donts.html
[gist1]: https://gist.github.com/francisbarton/3c9f755a7f17ce5624edb9d4da0f4f59
[ec_up]: https://www.design.upenn.edu/city-regional-planning/graduate/work/developing-new-metrics-transportation-safety-cyclist-and
@francisbarton
francisbarton / nominatim_problem.R
Created February 20, 2020 16:47
nominatim problem
<!-- language-all: lang-r -->
library(nominatim)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> Nominatim Usage Policy: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
#> MapQuest Nominatim Terms of Use: http://info.mapquest.com/terms-of-use/
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(raster)
@francisbarton
francisbarton / identical and near.md
Last active March 4, 2020 14:55
Learning about identical() and near()

In response to a [question from Stewart Lee][disqus-sl] (presumably not that one)

I have a numeric column and want to filter all number ending with (.999). Tried a couple of tricks and failed. Any suggestion?

suppressPackageStartupMessages(library(dplyr))
options(pillar.sigfig = 6)

# a misc. list of numbers just to test out my code against different targets
@francisbarton
francisbarton / setup test.Rmd
Last active June 30, 2020 18:21
Setup chunk test
---
title: "setup test"
output: html_document
---
```{r setup}
library(dplyr)
print("Hello")
```
@francisbarton
francisbarton / gist:89da88d3a199df701b7203985970e86b
Last active July 13, 2020 21:25
using if_else, mutate, map and reduce to create a data frame of columns meeting conditions
``` r
library(dplyr, warn.conflicts = FALSE)
library(purrr)
library(rlang, warn.conflicts = FALSE)
library(stringr)
filenames <- c("coronavirus_cases_202007061134.csv", "coronavirus_cases_202007071134.csv", "coronavirus_cases_202007081134.csv")
cases <- c(1000, 1500, 2000)
# couple of functions
@francisbarton
francisbarton / get_doogal_data.R
Created September 10, 2020 14:58
Use the doogal.co.uk API to get data about a postcode
# Use the doogal.co.uk API to get data about a postcode
# Doesn't accept a vector of codes all at once, so use with purrr::map_dfr()
# along a vector to combine results into a data frame
get_doogal_data <- function(postcode) {
data_names <- c(
"postcode",
"latitude",
"longitude",