Skip to content

Instantly share code, notes, and snippets.

View srvanderplas's full-sized avatar

Susan VanderPlas srvanderplas

View GitHub Profile
@srvanderplas
srvanderplas / Rpkginstall
Created May 2, 2024 15:00
Install all R packages loaded in any files within a folder
#!/bin/bash
# This concatenates array values using a multi-character separater.
# https://dev.to/meleu/how-to-join-array-elements-in-a-bash-script-303a
joinByString() {
local separator="$1"
shift
local first="$1"
shift
printf "%s" "$first" "${@/#/$separator}"
@srvanderplas
srvanderplas / ghcfix.sh
Created September 15, 2023 14:56
Script to fix up github classroom repositories, pull changes, and compile quarto homework files
#!/bin/bash
while getopts r::pvf OPT
do
case "$OPT" in
r) FILE="$OPTARG" # RENDER files with quarto
RENDER=1;;
v) VERBOSE=1;; # VERBOSE - print everything
p) PULL=1;; # Pull new changes
f) FIX=1;; # Fix github repo
esac
@srvanderplas
srvanderplas / Data Sources.md
Last active October 18, 2023 19:08
Useful Short Notes
@srvanderplas
srvanderplas / Examples.R
Last active April 20, 2022 14:50
Plotting with images
library(ggplot2)
library(dplyr)
library(stringr) # string manipulation
library(readr) # parse_number
library(magrittr) # pipe and set_names function
if(!"ggimage" %in% installed.packages()) {
install.packages("ggimage")
}
@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."))
@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 / 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 / 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 / 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 / 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