Skip to content

Instantly share code, notes, and snippets.

library(ggplot2)

# functions -----------------------------------------------

geom_liquid_area <- function(mapping = NULL, data = NULL, stat = "identity",
                             position = "stack", na.rm = FALSE, show.legend = NA,
                             inherit.aes = TRUE, ...) {
  layer(
    data = data,
@benmarwick
benmarwick / prentiss-1998-pca.R
Last active August 13, 2019 00:51
Exploring the PCA published by Prentiss (1998) to understand the usefulness of the Sullivan and Rozen debitage typology
#------------------------------------------------------
# Exploring the PCA published by Prentiss (1998) to understand the
# usefulness of the Sullivan and Rozen debitage typology
# read in & tidy the data -----------------------------------------------
library(tidyverse)
# got these data from table 7 (p. 644) of https://www.jstor.org/stable/2694112
# OCR'd using https://tabula.technology/
prentiss <- readr::read_csv("tabula-Prentiss 1988.csv")
@MilesMcBain
MilesMcBain / fools_five.R
Last active July 17, 2019 03:11
Fool's five
f <- function(...) {
function(df) with(df, ...)
}
footate <- function(.data, ...) {
dots <- list(...)
for (column in names(dots)) {
.data[[column]] <- dots[[column]](.data)
}
#===============================================================================
# 2019-07-19-- ikashnitsky.github.io
# Reproduce Figure 2 from http://doi.org/10.1007/s10708-018-9953-5
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
library(tidyverse)
library(hrbrthemes); import_roboto_condensed()
# the data as tribble
@emitanaka
emitanaka / collapseoutput.js
Created July 20, 2019 04:43
Collapsible Code Output for `xaringan`
<script>
(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() {
library(slide)
library(dplyr, warn.conflicts = FALSE)
# be careful not to `library(tsibble)` as it will overwrite slide()
# quarterly data to start with
df <- tibble(
dates = seq(as.Date("2019-01-01"), as.Date("2021-01-01"), by = "1 quarter"),
yq = tsibble::yearquarter(dates)
)
@ikashnitsky
ikashnitsky / pal-safe-five-and-six.R
Last active January 17, 2020 13:43
Safe and efficient palette of five colors for R -- https://twitter.com/ikashnitsky/status/1200570023334559745
#===============================================================================
# 2019-11-30 -- gist
# Safe and efficient palette of five colors, print and colorblind friendly
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
library(magrittr)
library(prismatic)
# a function to test color paletes quickly
@moodymudskipper
moodymudskipper / find classes
Last active November 6, 2020 04:42
find classes
# run from R GUI or you might have methods registered by IDE
# first method scrape S3 method tables, classes with no methods are not found
# second method parses code to find `class(foo) <- bar` lines and extracts string litterals if found, we could be a bit smarter there
# and find more, but that will still not be exhaustive, because we have things like `class(x) <- cl` and we'd have to check the code
# to see what `cl` is.
# we could also check if some objects are built with `structure`
# calls to `inherits` might also be checked
# The C code should also be inspected or we won't find for instance the "error" or "try-error" classes.