Skip to content

Instantly share code, notes, and snippets.

View seabbs's full-sized avatar
🏠
Working from home

Sam Abbott seabbs

🏠
Working from home
View GitHub Profile
@sharlagelfand
sharlagelfand / labeller
Created March 26, 2021 16:00
Demonstrating the usage of the argument `labeller = label_wrap_gen()` in the ggplot2 function facet_wrap()
library(ggplot2)
library(tibble)
df <- tribble(
~x, ~y, ~label,
1, 2, "A super long label oh god how am I going to deal with this",
2, 1, "A shorter one"
)
# Default - text is cut off
@jarvisc1
jarvisc1 / aa_plot_continent.r
Last active May 26, 2020 16:28
Plot range of Rt for continents
library(data.table)
library(ggplot2)
cases <- fread('_nowcasts/covid-global/national-summary/cases.csv')
df <- fread('_nowcasts/covid-global/national-summary/rt.csv')
continents <- fread('_nowcasts/covid-global/data/continents_cnty.csv')
cases <- cases[, .(country, date, cases = median)]
dfcont <- merge(df, continents, by.x = "country", by.y = "country_name", all.x = TRUE)
dfcont <- merge(dfcont, cases, by = c("country", "date"), all.x = TRUE)
library(future)
# //////////////////////////////////////////////////////////////////////////////
# Fresh R session takes around 40MB
pryr::mem_used()
#> Registered S3 method overwritten by 'pryr':
#> method from
#> print.bytes Rcpp
#> 35.7 MB
@seabbs
seabbs / data-read-plus-munge
Last active July 24, 2019 08:57
Read in, munge and save a set of csvs + profiling information
# Get required packages - managed using pacman ---------------------------
# This installs packages if they are missing and otherwise loads them.
if (!require(pacman)) install.packages("pacman"); library(pacman)
p_load("tidyverse")
p_load("fs")
p_load("data.table")
p_load("lubridate")
p_load("purrr")
p_load("furrr")
@seabbs
seabbs / spending_gap_normalised
Created June 7, 2019 10:37
Looking at normalised spending gap for global Tuberculosis funding
# Install and load the package --------------------------------------------
if(!require(pacman))install.packages("pacman")
pacman::p_load('dplyr', 'ggplot2', 'getTBinR')
pacman::p_load_gh('thomasp85/patchwork')
pacman::p_load_gh('bbc/bbplot')
# Look at available datasets\ ---------------------------------------------
available_datasets
#!/bin/bash
TODAY=`date +%Y-%m-%d`
TODAY_MD=`date +%B\ %d,\ %Y`
YEAR=`date +%Y`
PACKAGENAME=$1
##
## CHANGE ME!!!
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active May 17, 2025 10:34
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
## For password management
git config --global user.email "[email protected]"
git config --global user.name "Sam Abbott"
git config --global credential.helper cache
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
# github settings
# developer settings
# create access token and copy
# git pull/push
@cpsievert
cpsievert / app.R
Last active October 23, 2018 03:36
Targeting views
library(plotly)
library(shiny)
# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)
ui <- fluidPage(
mainPanel(
plotlyOutput("heat"),
@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