Skip to content

Instantly share code, notes, and snippets.

View vsbuffalo's full-sized avatar

Vince Buffalo vsbuffalo

View GitHub Profile
parseMS <- function(file) {
# simple MS parser
lns <- readLines(file)
header <- lns[1:3]
body <- lns[-c(1:3)]
brks <- body == "//"
groups <- cumsum(brks)
sims <- split(body, groups)
hpdi_stat <- function(x, prob=0.95) {
# stat functions for ggplot that handle HPDI from samples
# automatically.
hpdi <- HPDinterval(as.mcmc(x))
c(y=mean(x), ymin=hpdi[1, 'lower'], ymax=hpdi[1, 'upper'])
}

A 10 Minute Introduction to Creating R Packages with devtools

devtools is a terrific package that makes creating, developing, and debugging R packages fast and easy. I'll step through a ten minute introduction here. This is a short talk for labmates demonstrating how easy it is to create packages (with the right tools); most of this is just pointing Hadley's terrific book on R packages.

First, I add the following line to my ~/.zshrc file:

@vsbuffalo
vsbuffalo / unix-pipes.R
Created March 18, 2015 03:17
Yo dawg, I heard you like pipes, so I put a pipe in your pipe, so you can pipe streams while you pipe streams
library(magrittr)
write.table(iris, file="iris.txt", sep="\t", row.names=FALSE, quote=FALSE)
plines <- function(cmd) readLines(pipe(cmd))
ptabs <- function(cmd) read.delim(pipe(cmd))
# just as a trivial example, process some shuffled lines using GNU shuf, sort,
# etc. (we could do this in R, but this is to simulate command line operations)
# Sherman-Morrison formula for updating an inverted matrix
# includes R and C++ implementations, as well as benchmarks
library(microbenchmark)
library(RcppEigen)
library(Rcpp)
sourceCpp("sherman.cpp")
EPS <- 1e-8
@vsbuffalo
vsbuffalo / coal.js
Created April 21, 2015 03:25
dancing genealogies
function range(from, to, by) {
var by = typeof(by) === 'undefined' ? 1 : by;
var out = [];
for (var i = from; i <= to; i += by) out.push(i);
return out;
}
function sampleArrayWithoutReplacement(x, n) {
n = typeof x === 'undefined' ? 1 : n;
augroup Terminal
au!
au TermOpen * let g:last_terminal_job_id = b:terminal_job_id
augroup END
function! REPLSend(lines)
call jobsend(g:last_terminal_job_id, add(a:lines, ''))
endfunction
command! REPLSendLine call REPLSend([getline('.')])
@vsbuffalo
vsbuffalo / draw_lineage.js
Created September 5, 2015 16:53
example standlone d3 svg image generator
var fs = require('fs');
var d3 = require('d3');
var jsdom = require('node-jsdom');
var xmlserializer = require('xmlserializer');
var margin = {top: 2, right: 4, bottom: 2, left: 4};
var width = 200 - margin.left - margin.right,
height = 14 - margin.top - margin.bottom;
For every minute you are angry, you lose sixty seconds of happiness. ::: unknown
Anger is a momentary madness, so control your passion or it will control you. ::: Horace Walpole
When angry, count ten before you speak; if very angry, a hundred. ::: Jefferson
Anger is a wind which blows out the lamp of the mind. ::: Robert G. Ingersoll
Holding on to anger is like grasping a hot coal with the intent of throwing it at someone else; you are the one getting burned. ::: Buddha
The best remedy for a short temper is a long walk. ::: Jacqueline Schiff
@vsbuffalo
vsbuffalo / Makefile
Last active November 28, 2018 14:04
finally, a LaTeX makefile that captures your anger and frustration
# Thanks https://github.com/EBI-predocs/latex-thesis/blob/master/Makefile for
# some tips
LATEXMK = latexmk -xelatex
# CONFIG
target = manuscript
references = bib.bib
# SETUP
includes := $(shell ls *.tex) ${references}