Skip to content

Instantly share code, notes, and snippets.

View srvanderplas's full-sized avatar

Susan VanderPlas srvanderplas

View GitHub Profile
@srvanderplas
srvanderplas / table-grob.R
Created November 27, 2018 18:08
Attempt at grob-based table
main.table <- data.frame(Results = c("Exclusion", "Identification"), `Same Source` = c("Missed Identification", "Correct Identification"), `Different Source` = c("Correct Exclusion", "Wrong Identification"))
names(main.table) <- c("", "Same Source", "Different Source")
blank <- textGrob("")
gt <- textGrob("Ground Truth", gp = gpar(fontsize = 14, fontface = "bold"))
res <- textGrob("Results", rot = 90, gp = gpar(fontsize = 14, fontface = "bold"))
mt <- tableGrob(main.table, rows = NULL, theme = ttheme_default())
layout.matrix <- matrix(c(1, 1, 2, 2, 3, 4, 4, 4, 5, 4, 4, 4, 5, 4, 4, 4), nrow = 4, byrow = T)
@srvanderplas
srvanderplas / app.R
Created December 13, 2018 16:04
Tiny Shiny App for checking path issues
shinyApp(ui = fluidPage(textOutput("pwd")),
server = function(input, output) {
output$pwd <- renderText(list.files(here::here()))
})
@srvanderplas
srvanderplas / app.R
Created December 13, 2018 16:13
Tiny Shiny App for debugging ODBC connections
shinyApp(ui = fluidPage(textOutput("con"), textOutput("fileexists")),
server = function(input, output) {
output$con <- renderPrint(con)
output$fileexists <- renderPrint(list.files(here::here()))
})
@srvanderplas
srvanderplas / Scrape_Weather.R
Created January 15, 2019 03:29
Weather from TimeAndDate.com
library(RSelenium)
library(rvest)
library(tidyverse)
# Newer versions of Selenium don't work that well...
rs_driver <- rsDriver(port = 4567L, version = "3.12.0")
rd <- rs_driver$client
rd$setImplicitWaitTimeout(milliseconds = 5000)
url <- function(m, y) sprintf("https://www.timeanddate.com/weather/@4846834/historic?month=%d&year=%d", m, y)
@srvanderplas
srvanderplas / thumbnail.sh
Created January 31, 2019 19:21
Thumbnails from stl files
#!/bin/bash
for i in *.stl;
do T=__tmp__$i;
b=`basename $i`;
echo import\(\"$i\"\)\;
>$T;
openscad -o $b.png --render --colorscheme=Nature --camera0,0,0,30,-30,0 --imgsize=600,600 --projection=o $T;
rm $T;
done
@srvanderplas
srvanderplas / Attempt_at_reticulate.R
Last active February 1, 2019 14:08
Stub of a function to get Hough Line information out of opencv in python
library(reticulate)
library(tidyverse)
library(stringr)
library(imager)
main <- import_main()
cv2 <- import("cv2", as = "cv2")
source_python("./inst/HoughLines.py")
chunk_edges <- list.files("inst/processed/slices/", pattern = "_edge", full.names = T)
@srvanderplas
srvanderplas / FullProcess.sh
Created February 1, 2019 14:09
Bash script to slice images up into smaller images (with an offset) in parallel, save each image, and remove all blank images
#!/bin/bash
# This uses GNU parallel: cite:
# @article{Tange2011a,
# title = {GNU Parallel - The Command-Line Power Tool},
# author = {O. Tange},
# address = {Frederiksberg, Denmark},
# journal = {;login: The USENIX Magazine},
# month = {Feb},
# number = {1},
@srvanderplas
srvanderplas / ScrapePowerPools.R
Created April 26, 2019 15:50
Scrape Power Pool Data (from 2014)
#!/usr/bin/Rscript
# Scrape Southwest Power Pool LMP/SMP/MCC
library(scrapeR)
library(stringr)
library(lubridate)
library(ggplot2)
library(RMySQL)
library(plyr)
library(reshape2)
@srvanderplas
srvanderplas / bunch_murphy_sim.R
Created April 23, 2020 15:37
R code to simulate Bunch & Murphy (2003) test of forensic identification of cartridge cases
# Bunch and Murphy simulation
library(tidyverse)
# Packet 1 contains 10 fires from the same weapon
# Packet 2 contains 1 from each of the other 9 glocks, plus one non-glock
# Packets 3-8 contain
# - 0, 1, or 2 non-glocks
# - 10, 9, or 8 randomly sampled from each of the other glocks
# After packet 2 is assembled, then, the following cartridges remain:
@srvanderplas
srvanderplas / publication_processing.R
Last active October 12, 2020 20:04
Process figures from tex file for Stat journal submission
# This processes figures for STAT guidelines...
library(tidyverse)
library(stringr)
# --- Pull out all figure captions and reference names ---
chunks <- readLines("index.tex")
figures_start <- which(str_detect(chunks, "\\\\begin.figure."))
figures_end <- which(str_detect(chunks, "\\\\end.figure."))