Skip to content

Instantly share code, notes, and snippets.

@cwickham
cwickham / .gistr
Created November 16, 2022 21:13
R objects for ST499/599 final
gistr
@cwickham
cwickham / final_r_objects.rda
Created November 16, 2022 20:56
R objects for ST499/599 final
RDX3
X
data.frame
@cwickham
cwickham / 00_bind_rows.Rmd
Last active November 26, 2018 21:36
Example of combining `bind_rows()` with `map()` and `read_csv()`
---
title: Example of combining `bind_rows()` with `map()` and `read_csv()`
output: github_document
---
```{r}
library(tidyverse)
```
If you have some data files with a similar structure:
@cwickham
cwickham / .block
Last active November 7, 2018 21:37 — forked from jakevdp/.block
Multi-Value Tooltip in Vega-Lite
license: MIT
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vega@4"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@3.0.0-rc1"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
</head>
<body>
<div id="vis"></div>
@cwickham
cwickham / read_hurricanes.R
Last active August 16, 2019 13:49
A line by line stye of reading in the hurricane data
library(tidyverse)
library(xml2)
url <- "http://www.aoml.noaa.gov/hrd/hurdat/hurdat2-nepac.html"
# Import ------------------------------------------------------------------
hurricanes <- read_html(url) %>%
xml_find_first(".//pre") %>%
xml_text() %>%
@cwickham
cwickham / hurricanes.R
Created July 30, 2018 13:17
Import messy hurricane data
library(tidyverse)
library(xml2)
url <- "http://www.aoml.noaa.gov/hrd/hurdat/hurdat2-nepac.html"
# Column names ------------------------------------------------------------
# From: http://www.aoml.noaa.gov/hrd/hurdat/newhurdat-format.pdf
# for the data lines
wind_vars <- cross_df(list(
1 2
3 4
library(sp)
library(tmap)
library(tigris)
# devtools::install_github("cwickham/geospatial")
library(geospatial)
nyc_tracts <- tracts(state = "NY", county = "New York", cb = TRUE)
nyc_tracts_merge <- merge(nyc_tracts, nyc_income, by.x = "TRACTCE", by.y = "tract")
qtm(nyc_tracts_merge, fill = "estimate")
@cwickham
cwickham / oauth-functions.R
Last active November 16, 2015 06:25
httr authentication functions for fitbit API
# edited from init_oauth2.0 to:
# * add trailing slash to callback
# * add base64 encoded client_id:client_secret to request when exchanging
init_oauth2.0_fitbit <- function(endpoint, app, scope = NULL, type = NULL,
use_oob = getOption("httr_oob_default"),
is_interactive = interactive()) {
if (!use_oob && !httr:::is_installed("httpuv")) {
message("httpuv not installed, defaulting to out-of-band authentication")
use_oob <- TRUE