This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple approach to visually-weighted regression plots | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ggplot2", "reshape2", "MASS") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Generate some data: | |
nn <- 1000 | |
myData <- data.frame(X = rnorm(nn), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## See http://gettinggeneticsdone.blogspot.com/2013/06/customize-rprofile.html | |
## Load packages | |
library(BiocInstaller) | |
## Don't show those silly significanct stars | |
options(show.signif.stars=FALSE) | |
## Do you want to automatically convert strings to factor variables in a data.frame? | |
## WARNING!!! This makes your code less portable/reproducible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* I add this to html files generated with pandoc. | |
*/ | |
html { | |
font-size: 100%; | |
overflow-y: scroll; | |
-webkit-text-size-adjust: 100%; | |
-ms-text-size-adjust: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
next_letter <- local({ | |
i <- 0 | |
function() { | |
i <<- i + 1 | |
paste0("x_", c(letters, LETTERS))[i] | |
} | |
}) | |
f <- function() { | |
new_arg <- alist(x = ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a <- 1 | |
b <- 2 | |
ftw <- function() | |
{ | |
vars <- ls(envir = .GlobalEnv) | |
rm(list = vars, envir = .GlobalEnv) | |
} | |
ftw() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' The goals here are to: | |
#' (1) play around with themes to make base graphics less ugly | |
#' (2) atomically specify multiple plot aspects (data, axes, grid, title) in a single call | |
#' (3) Recycle last plot theme to easily duplicate its appearance in the next plot | |
#' The idea is to create a set of customizable functions like `theme()`, which return a list of graphics arguments | |
#' These can then be passed to `splot`, which will cleanly handle them by passing some to `par` and some to `plot` | |
#' Different `theme()` functions can then be used to modify color palettes, axes, etc. | |
merge.list <- | |
function (x, y) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rasmusab/beepr package is great for telling you when your R code finishes running. | |
# But if the code throws an error, the beep will never come, and you won't know that | |
# it finished running until you visually check. | |
# Solution: change the error handler to a failure beep. | |
# Example | |
foo <- function(success = TRUE) { | |
if (!success) { | |
stop("Error!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(jsonlite) | |
## Download | |
pkgs <- fromJSON("http://crandb.r-pkg.org/-/events") | |
## Filter | |
na_pkgs <- unique(pkgs$name[ is.na(pkgs$date) ]) | |
events <- pkgs[ ! pkgs$name %in% na_pkgs, c("date", "name", "event")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat | |
# Originally seen at http://spatial.ly/2014/08/population-lines/ | |
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess, | |
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after | |
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line. | |
# The result of the code below can be seen at http://imgur.com/ob8c8ph | |
library(tidyverse) |
OlderNewer