Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
library(duckdb)
#> Loading required package: DBI
library(glue)

url <- "http://www.env.gov.bc.ca/wsd/data_searches/water/Discharge.csv"

conn <- DBI::dbConnect(duckdb(), ":memory:")

# Install and load duckdb extensions to read from http
library(arrow)
#> 
#> Attaching package: 'arrow'
#> The following object is masked from 'package:utils':
#> 
#>     timestamp
library(duckdb)
#> Loading required package: DBI
library(dplyr)
@ateucher
ateucher / setup-gh-cli-auth-2fa.md
Last active June 28, 2022 07:16
Setup git on the CLI to use 2FA with GitHub

These are instructions for setting up git to authenticate with GitHub when you have 2-factor authentication set up. This authentication should be inherited by any GUI client you are using. These are intentionally brief instructions, with links to more detail in the appropriate places.

  1. Download and install the git command-line client (if required).

  2. Open the git bash window and introduce yourself to git (if required):

    git config --global user.name 'Firstname Lastname'
    git config --global user.email 'firstname.lastname@gov.bc.ca'
    
@ateucher
ateucher / extract_pptx_notes.R
Last active May 19, 2022 23:48
Extract notes from a pptx slide and export to markdown or docx
extract_pptx_notes <- function(pp_file, format = c("md", "docx")) {
if (!requireNamespace("officer", quietly = TRUE))
stop("pacakge 'officer' required.")
if (!requireNamespace("xml2", quietly = TRUE))
stop("pacakge 'xml2' required.")
if (!requireNamespace("rmarkdown", quietly = TRUE))
stop("pacakge 'rmarkdown' required.")
if (!requireNamespace("glue", quietly = TRUE))
stop("pacakge 'glue' required.")
@ateucher
ateucher / if_ifelse.md
Created July 7, 2017 20:22
R: if vs ifelse

R: if vs ifelse

Inspired by a question about when to use if vs ifelse

First we'll make a simple function that determines whether or not someone is awesome:

is_awesome &lt;- function(name) {
author date output title
ateucher
2021-06-08
reprex::reprex_document
ash-crane_reprex.R
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
@ateucher
ateucher / bc-hydro-outages.R
Created May 6, 2021 23:36
bc-hydro-outages.R
library(sf)
library(jsonlite)
library(purrr)
library(mapview)
f <- read_json("https://www.bchydro.com/power-outages/app/outages-map-data.json")
polys <- lapply(f, function(x) {
mat <- matrix(unlist(x$polygon), ncol = 2, byrow = TRUE)
st_polygon(list(rbind(mat, mat[1,])))
@ateucher
ateucher / covid-canada.R
Last active December 3, 2020 00:24
covid-canada.R
library(tidyverse)
library(gghighlight)
library(ggrepel)
library(scales)
data <- read_csv("https://github.com/CSSEGISandData/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")
data_long <- pivot_longer(data, `1/22/20`:last_col(), names_to = "date", values_to = "cases") %>%
mutate(date = as.Date(date, format = "%m/%d/%y")) %>%
filter(!is.na(cases),
library(ggplot2)

iris$is_pretty <- sample(c(TRUE, FALSE), nrow(iris), replace = TRUE)

# dodge < width
ggplot(iris, aes(y = is_pretty, x = Petal.Length, fill = Species)) + 
  geom_bar(stat = "identity", position = position_dodge(0.5), width = 0.85)

@ateucher
ateucher / ggplot_guides.R
Last active May 30, 2020 19:41
Manipulating ggplot2 legend with `override.aes` so points only for points, lines only for lines etc.
require(ggplot2)
set.seed(42)
df <- data.frame(x=1:50, y=rnorm(50, 10, 2), int=rbinom(50,1,0.3))
ggplot(df, aes(x=x, y=y)) +
geom_ribbon(aes(ymin=0, ymax=y, fill='#1E90FF'), alpha=0.3) +
geom_abline(intercept=10, slope=-0.1
, aes(colour='Linear')) +