Skip to content

Instantly share code, notes, and snippets.

@aaronwolen
aaronwolen / rnw2rmd.sh
Created December 1, 2015 12:53
Convert Rnw presentations to Rmarkdown files
#!/bin/bash
# Partially convert Rnw presentations to Rmd syntax
# - [x]: Code chunks
# - [x]: Section headers
# - [x]: Slide headers
# - [x]: Presenter notes
# - [x]: Lists
# - [ ]: Inlinde code (sort of, not really)
@aaronwolen
aaronwolen / matrix-benchmark.Rmd
Last active August 29, 2015 14:24
Benchmark for converting matrixes to tidy data.frames in R
```{r}
library(microbenchmark)
set.seed(1024)
nr <- 1e4
nc <- 100
m <- matrix(runif(nr * nc), nrow = nr,
dimnames = list(paste0("g", seq_len(nr)),
paste0("s", seq_len(nc))))
@aaronwolen
aaronwolen / matrix-benchmark.md
Created July 2, 2015 16:25
Benchmark for converting matrixes to tidy data.frames in R

library(microbenchmark)

set.seed(1024) nr <- 1e4 nc <- 100

m <- matrix(runif(nr * nc), nrow = nr, dimnames = list(paste0("g", seq_len(nr)), paste0("s", seq_len(nc))))

@aaronwolen
aaronwolen / calendarHeat.R
Last active October 26, 2020 21:30
Calendar Heatmap by Paul Bleicher
##############################################################################
# Calendar Heatmap #
# by #
# Paul Bleicher #
# an R version of a graphic from: #
# http://stat-computing.org/dataexpo/2009/posters/wicklin-allison.pdf #
# requires lattice, chron, grid packages #
##############################################################################
## calendarHeat: An R function to display time-series data as a calendar heatmap
@aaronwolen
aaronwolen / newkindofscience.r
Created April 10, 2015 17:37
Simple R implementation of cellular automata described in A New Kind of Science.
# A few simple rules from Stephen Wolfram's A New Kind of Science
apply_rule <- function(x, rule = "254") {
stopifnot(length(x) == 3)
stopifnot(all(x %in% c(0, 1)))
rules <- list("254" = c(1, 1, 1, 1, 1, 1, 1, 0),
"250" = c(1, 1, 1, 1, 1, 0, 1, 0),
"90" = c(0, 1, 0, 1, 1, 0, 1, 0),
"30" = c(0, 0, 0, 1, 1, 1, 1, 0))
@aaronwolen
aaronwolen / toggleFullscreen.scpt
Last active August 29, 2015 14:16
Toggle fullscreen mode for OS X applications depending on display size
(*
display-specific fullscreen behavior
enable fullscreen for specific applications on MacBook and disable fullscreen
when using a larger external display
adapted from:
* https://gist.github.com/dsummersl/4175461
* http://daringfireball.net/2006/12/display_size_applescript_the_lazy_way
*)
@aaronwolen
aaronwolen / clean-pdata.r
Last active January 19, 2016 17:41
Clean GEO phenoData characteristics columns
#' Extract labels and values from phenoData characteristics columns
#'
#' @details
#' characteristics_ch1.1 characteristics_ch1.2 age batch
#' age:54 batch:1 --> 54 1
#' age:35 batch:2 35 2
parse_characteristics <- function(x, sep = ": ") {
@aaronwolen
aaronwolen / iplotmap-searchbox.Rmd
Last active August 29, 2015 14:09
qtlcharts::iplotMap() search box
---
title: "test"
output:
html_document:
keep_md: yes
---
```{r}
library(qtl)
library(qtlcharts)
@aaronwolen
aaronwolen / dendrogram-contigs.r
Created November 12, 2014 16:22
Identify clusters of contiguous factors within a dendrogram
# Identify clusters of contiguous factors within a dendrogram
# Aaron Wolen
#
# See http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0038422
# for an example situation in which this would be useful
#
# x: dendrogram
# f: a named vector containing the factor that defines the grouping of leaves,
# must be named using the same values that define x's leaf labels
@aaronwolen
aaronwolen / unembed.r
Last active August 29, 2015 14:07
Extract and append multiple values embedded in rows
# Extract and append multiple values embedded in rows
#
# data: data.frame
# col: column name containing embedded values
# sep: regular expression to split column by
#
# df <- data.frame(key = c("a", "a;b", "a;b;c"), val = 1:3)
# unembed(df, "key", ";")
unembed <- function(data, col, sep, ...) {