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
#!/bin/bash | |
FN=`basename "$1"` | |
TMPFILE=`mktemp -t gitxlscmp."${FN}"` || exit 1 | |
git show HEAD:"$1" > "$TMPFILE" | |
open -a "Microsoft Excel" "$TMPFILE" "$1" | |
# Want to delete $TMPFILE once open in Excel, | |
# but $(open) returns immediately, so check for ourselves | |
until lsof -a -c "Microsoft Excel" "$TMPFILE" > /dev/null; do |
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
R version 3.2.2 (2015-08-14) -- "Fire Safety" | |
Copyright (C) 2015 The R Foundation for Statistical Computing | |
Platform: x86_64-redhat-linux-gnu (64-bit) | |
> packageVersion("ggplot2") | |
[1] ‘1.0.1’ | |
> library(ggplotTicks) | |
Error in library(ggplotTicks) : there is no package called ‘ggplotTicks’ | |
> library(devtools) |
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
# Sample data: 2x2 manipulation, replicated 4x, multiple responses measured repeatedly over time. | |
# The response variables aren't related: y_also doesn't come "after" y_1 in any meaningful sense. | |
df = expand.grid( | |
day=1:3, | |
replicate=1:4, | |
t1=c("ctrl", "more"), | |
t2=c("ambient", "manipulated")) | |
df$y_1 = rnorm(48) | |
df$y_other = runif(48) | |
df$y_also = rlnorm(48) |
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
strs = c("nomatch", "Odum 1969", "2001FACE_3b", "1800", "sdfghj1928qwer") | |
strs_yrs = gsub(".*((19|20)[0-9]{2}).*", "\\1", strs) | |
strs_yrs | |
# [1] "nomatch" "1969" "2001" "1800" "1928" | |
# Oops, strings with no year (or year from wrong century) are returned unchanged! Let's remove them separately: | |
strs_haveyr = grepl("(19|20)[0-9]{2}", strs) | |
strs_yrs[!strs_haveyr] = "" | |
strs_yrs | |
# [1] "" "1969" "2001" "" "1928" |
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
R version 3.2.3 (2015-12-10) | |
Platform: x86_64-apple-darwin13.4.0 (64-bit) | |
Running under: OS X 10.11.3 (El Capitan) | |
locale: | |
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 | |
attached base packages: | |
[1] stats graphics grDevices utils datasets base |
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
anycolors = function(n)rgb(runif(n), runif(n), runif(n)) | |
color_grid = function(x, y, nx=10, ny=nx){ | |
g = expand.grid( | |
x=seq(min(x), max(x), by=diff(range(x))/nx), | |
y=seq(min(y), max(y), by=diff(range(y))/ny)) | |
g$color = anycolors(nrow(g)) | |
g | |
} |
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(ggplot2) | |
library(dplyr) | |
library(lubridate) | |
dates = c( | |
seq(from=as.Date("2014-10-01"), to=as.Date("2015-05-30"), by="days"), | |
seq(from=as.Date("2015-10-01"), to=as.Date("2016-05-30"), by="days")) | |
Tmin = rnorm(length(dates), mean=10*sin((yday(dates) - 90)/365*2*pi)) | |
Tmax = Tmin + rnorm(length(dates), mean=5) |
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 have a vector of strings that map to known numeric values. | |
# What's the cleanest/most reader-friendly R idiom for this conversion? | |
# sample data | |
df = expand.grid( | |
x_str = c("string1", "secondstring", "blah", "garbagestring"), | |
replicate=1:3, | |
stringsAsFactors=FALSE) | |
# Approach 1: Encode the look-up table as its own dataframe |
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
# Demo of intermittent plotting failures. | |
# Apparent requirements: | |
# * Interactive session (I'm in R.app using Quartz graphics) | |
# * Arranging multiple figures using gridExtra::arrangeGrob | |
# * Very different figure complexities | |
# (i.e one plot big enough to have a rendering lag, one that renders much faster.) | |
# * No graphics device open at beginning of arrangeGrob call | |
# Gentle reader, can you reproduce this on your machine? |
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(dplyr) | |
gather = tidyr::gather | |
df = data.frame( | |
one=c(1,NA,NA,3, NA), | |
two=c(NA,3,NA,4,NA), | |
three=c(NA,NA,2,NA,5), | |
x=rnorm(5)) | |
result = (df |