Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Finishing up 2020

Nicholas Tierney njtierney

:octocat:
Finishing up 2020
View GitHub Profile
View exchange-rates.R
# (1) Get a free plan from https://openexchangerates.org/signup/free
# (2) Tell this function your API key:
# from this section of the site: https://openexchangerates.org/account/app-ids
# Sys.setenv(OER_KEY = "paste-your-very-long-numeric-string-here")
Sys.setenv(OER_KEY = "OER_KEY")
library(glue)
library(tidyverse)
get_day <- function(day) {
u <- glue("https://openexchangerates.org/api/historical/{day}.json?app_id=\\
@njtierney
njtierney / matrix_to_data.frame.R
Created Jan 4, 2017 — forked from aammd/matrix_to_data.frame.R
cantrip to turn a matrix into a data.frame, assuming that the first row of the matrix contains a header row
View matrix_to_data.frame.R
matrix_to_df_firstline_header <- function(mat){
requireNamespace("purrr")
mat %>%
## cut columns into lists
apply(2, function(s) list(s)) %>%
flatten %>%
map(flatten_chr) %>%
## set names to the first element of the list
{set_names(x = map(., ~ .x[-1]),
@njtierney
njtierney / Makefile
Created Sep 20, 2016 — forked from PirateGrunt/Makefile
Basic makefile
View Makefile
####################
# Makefile
# Copyright Brian A. Fannin 2015
####################
RDIR = .
DATA_DIR = $(RDIR)/data
GATHER_DIR = $(DATA_DIR)/gather
GATHER_SOURCE = $(wildcard $(GATHER_DIR)/*.Rmd)
@njtierney
njtierney / advise.md
Created Aug 18, 2016 — forked from hadley/advise.md
Advise for teaching an R workshop
View advise.md

I think the two most important messages that people can get from a short course are:

a) the material is important and worthwhile to learn (even if it's challenging), and b) it's possible to learn it!

For those reasons, I usually start by diving as quickly as possible into visualisation. I think it's a bad idea to start by explicitly teaching programming concepts (like data structures), because the pay off isn't obvious. If you start with visualisation, the pay off is really obvious and people are more motivated to push past any initial teething problems. In stat405, I used to start with some very basic templates that got people up and running with scatterplots and histograms - they wouldn't necessary understand the code, but they'd know which bits could be varied for different effects.

Apart from visualisation, I think the two most important topics to cover are tidy data (i.e. http://www.jstatsoft.org/v59/i10/ + tidyr) and data manipulation (dplyr). These are both important for when people go off and apply