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 / 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.")
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)

*.png
*.pdf
.DS_Store
.Rhistory
# install.packages(c("bcdata", "dplyr", "remotes"))
# remotes::install_github("bcgov/rems")
library(rems)
library(bcdata)
library(dplyr)
# Get the watershed boundary - I don't know if this is exactly the boundary you
# want but you could read in any spatial file you have instead using the sf package. Eg:
# columbia <- sf::read_sf("path-to-my-columbia-boundary.shp")
columbia <- bcdc_query_geodata("eaubc-freshwater-ecoregions") %>%
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0

system("ogr2ogr --version", intern = TRUE)
#> [1] "GDAL 2.4.2, released 2019/06/28"
system("proj", intern = TRUE)
#> character(0)

file <- system.file("gpkg/tl.gpkg", package = "sf")