Skip to content

Instantly share code, notes, and snippets.


Colin Gillespie csgillespie

View GitHub Profile
emitanaka / collapseoutput.js
Created Jul 20, 2019
Collapsible Code Output for `xaringan`
View collapseoutput.js
(function() {
var divHTML = document.querySelectorAll(".details-open");
divHTML.forEach(function (el) {
var preNodes = el.getElementsByTagName("pre");
var outputNode = preNodes[1];
outputNode.outerHTML = "<details open class='output'><summary>Output</summary>" + outputNode.outerHTML + "</details>";
(function() {
gadenbuie / join-animations-with-gganimate.R
Last active Jan 11, 2022
Animated dplyr joins with gganimate
View join-animations-with-gganimate.R
# Animated dplyr joins with gganimate
# * Garrick Aden-Buie
# *
# * MIT License:
# Note: I used Fira Sans and Fira Mono fonts.
# Use search and replace to use a different font if Fira is not available.
csgillespie /
Last active Oct 31, 2019
Foundational data science with R


Please make sure you are using a recent version of R (current version is 3.6.X) - the final digit is the minor version number. The essential numbers are the first two. You can check the version of R you are running via


Please install the latest version of RStudio (

View europe.R
# data from
# Originally seen at
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at
gaborcsardi / cran-over-time.R
Last active Jul 18, 2020
Size of the CRAN R package repository over time
View cran-over-time.R
## Download
pkgs <- fromJSON("")
## Filter
na_pkgs <- unique(pkgs$name[$date) ])
events <- pkgs[ ! pkgs$name %in% na_pkgs, c("date", "name", "event")]
View beepr_error.R
# rasmusab/beepr package is great for telling you when your R code finishes running.
# But if the code throws an error, the beep will never come, and you won't know that
# it finished running until you visually check.
# Solution: change the error handler to a failure beep.
# Example
foo <- function(success = TRUE) {
if (!success) {
leeper / plotthemes.R
Last active Oct 28, 2016
Experimenting with themes in base graphics
View plotthemes.R
#' The goals here are to:
#' (1) play around with themes to make base graphics less ugly
#' (2) atomically specify multiple plot aspects (data, axes, grid, title) in a single call
#' (3) Recycle last plot theme to easily duplicate its appearance in the next plot
#' The idea is to create a set of customizable functions like `theme()`, which return a list of graphics arguments
#' These can then be passed to `splot`, which will cleanly handle them by passing some to `par` and some to `plot`
#' Different `theme()` functions can then be used to modify color palettes, axes, etc.
merge.list <-
function (x, y) {
View ftw.R
a <- 1
b <- 2
ftw <- function()
vars <- ls(envir = .GlobalEnv)
rm(list = vars, envir = .GlobalEnv)
View self-modification.r
next_letter <- local({
i <- 0
function() {
i <<- i + 1
paste0("x_", c(letters, LETTERS))[i]
f <- function() {
new_arg <- alist(x = )
killercup / pandoc.css
Created Jul 3, 2013
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
View pandoc.css
* I add this to html files generated with pandoc.
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;