Skip to content

Instantly share code, notes, and snippets.

View kbroman's full-sized avatar

Karl Broman kbroman

View GitHub Profile
options(error = function() {
library(RPushbullet)
pbPost("note", "Error", geterrmessage())
if(!interactive()) stop(geterrmessage())
})
stop("this is an error")
message("Shouldn't get here")
myscript.js: myscript.coffee
coffee -bc $<
myscript.js: myscript.coffee
coffee -bc $<
myscript.js: myscript.coffee
coffee -bc $<
@kbroman
kbroman / slider example
Last active August 29, 2015 14:08
slider with d3
# empty file with initial underscore, to give the gist a better name
# if laundry contains n_pair pairs of socks and n_sing singletons,
# how many socks to draw to get first pair?
sim_socks <-
function(n_pair=21, n_sing=3, n_sim=100000)
{
socks <- c(rep(1:n_pair, 2), n_pair+(1:n_sing))
# replicate(n_sim, min(which(duplicated(sample(socks)))))
library(magrittr)
# convert c("female", "Male") to c(0,1)
# magrittr is way nicer than nested function calls
convert_sexcodes <-
function(codes)
{
require(magrittr)
tolower(codes) %>%
options(show.signif.stars=FALSE, scipen=10, htmlhelp=TRUE)
options(width=115, repos="http://cran.rstudio.com",
CRAN = "http://cran.rstudio.com",
browserNLdisabled = TRUE,
deparse.max.lines = 2)
if (interactive()) {
suppressMessages(require(devtools))
}
options(error= function() cat(" \\\ \n \\\
A regular code chunk:
```{r regular}
data(cars)
summary(cars)
```
A verbatim code chunk:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<link
href="http://arxiv.org/api/query?search_query%3Dti%3Adeconvolution%20AND%20submittedDate%3A%5B199001010000%20TO%20201409062400%5D%26id_list%3D%26start%3D0%26max_results%3D2"
rel="self" type="application/atom+xml"/>
<title type="html">ArXiv Query: search_query=ti:deconvolution AND
submittedDate:[199001010000 TO
201409062400]&amp;id_list=&amp;start=0&amp;max_results=2</title>
<id>http://arxiv.org/api/PmrTD7mnJhK1VVvONMZIkrVVdAg</id>
<updated>2014-09-09T00:00:00-04:00</updated>