Skip to content

Instantly share code, notes, and snippets.

View drewhendrickson's full-sized avatar

Drew Hendrickson drewhendrickson

View GitHub Profile
@article{Langsford2018quantify,
title={Quantifying sentence acceptability measures: Reliability, bias, and variability},
author={Langsford, Steven, Perfors, Amy, Hendrickson, Andrew T, Kennedy, Lauren A., & Navarro, Danielle J.},
journal={Glossa: a journal of general linguistics},
volume={3},
number={1},
year={2018},
doi={http://doi.org/10.5334/gjgl.396}
}
@drewhendrickson
drewhendrickson / sample_build_cooccurance_matrix.R
Created July 22, 2017 17:45
R code to build a co-occurnace matrix from two clustering solutions
# build some sample data
entries = 1000
data <- data.frame(nomem_encr = round(runif(entries, 100, 10000)),
Cluster.x = sample(1:4, entries, replace=T),
Cluster.y = sample(1:4, entries, replace=T))
# check that my sample data looks ok
head(data)
# get the unique cluster labels for each dimension
@drewhendrickson
drewhendrickson / TaxonomicThematicStimuli.csv
Last active December 13, 2016 15:29
Stimuli from Experiment 2 of CogSci submission: Quantifying the time course of similarity
Target Taxonomic Thematic Source
SPOON LADLE CEREAL GentnerBrem1999
ROCKET MISSILE ASTRONAUT GentnerBrem1999
GARLIC ONION VAMPIRE GentnerBrem1999
MILK LEMONADE COW WisniewskiBassok1999
SHIP CANOE SAILOR WisniewskiBassok1999
CAR PICKUP TRUCK MECHANIC WisniewskiBassok1999
CHAIR BED CARPENTER WisniewskiBassok1999
TELEPHONE TAPE RECORDER RECEPTIONIST WisniewskiBassok1999
TIE DRESS MAN WisniewskiBassok1999
```
$ Rscript --vanilla R/myscript.R 12 &> logs/myscript.log &
```
Rscript runs the .R file as a standalone script, without going into the R environment.
The –vanilla flag means that you run the script without calling in your .Rprofile
(which is typically set up for interactive use) and without prompting you to save a workspace image.
I always run the Rscript from the save level to that which is set as the project root for Rstudio
to avoid any problems because of relative paths being set up wrongly.
The number after the .R file to be run is the number of cores you want to run the parallel stuff on.
@drewhendrickson
drewhendrickson / gist:7742291
Created December 1, 2013 23:28
Sample plot showing how to transform ggplot2 histogram from frequency to percent.
require(ggplot2)
agg_progress <- data.frame(id=rep(letters[1:10], each=6),
Var1=rep(LETTERS[1:6], times=10),
Freq=floor(100 * runif(60)))
# As frequency
ggplot(agg_progress) + theme_bw() +
@drewhendrickson
drewhendrickson / r_snips
Last active December 27, 2015 10:59
Snippits of R code
# without
"%w/o%" <- function(x, y) x[!x %in% y]
# when an error occurs, invoke debug mode
options(error = browser)
# an R array produces a 1D JS array
# an R list containing JS arrays (strings) produces a 2D JS array
write.js.array <- function(l) {
out <- "["
@drewhendrickson
drewhendrickson / rmdToPdf
Created May 24, 2013 03:35
Simple bash script for converting an Rmd file to pdf. Requires Rscript (in utils package of R) and pandoc (http://johnmacfarlane.net/pandoc/)
#!/bin/bash
Rscript -e "library(knitr); knit('$1.Rmd')"
pandoc -o $1.pdf $1.md