Skip to content

Instantly share code, notes, and snippets.

View jimhester's full-sized avatar

Jim Hester jimhester

View GitHub Profile
jimhester / less.R
Last active August 29, 2015 14:03
less function for R
withOptions <- function(optlist, expr)
oldopt <- options(optlist)
expr <- substitute(expr)
less = function(x) {
withOptions(list(pager='less', dplyr.print_min=.Machine$integer.max, width=10000L), page(x, method='print'))
jimhester / pre-commit
Last active August 29, 2015 14:07
Travis pre-commit hook for R projects
# To use, place this script in your project .git/hooks directory.
# The script will automatically run run_tests before committing, so you won't break your project!.
# Modified from
# script to run tests on what is to be committed
# First, stash index and work dir, keeping only the
# to-be-committed changes in the working directory.
old_stash=$(git rev-parse -q --verify refs/stash)
git stash save -q --keep-index
jimhester / .Rbuildignore
Created October 31, 2014 14:05
#' ---
#' title: "Notebook Example"
#' author: "Jim Hester"
#' date: "`r Sys.Date()`"
#' output: rmarkdown::html_vignette
#' vignette: >
#' %\VignetteIndexEntry{Notebook example}
#' %\VignetteEngine{knitr::rmarkdown}
#' %\usepackage[utf8]{inputenc}
#' ---
jimhester / error_messages.R
Last active August 29, 2015 14:11
More informative error messages for R
# missing variable
`$` <- function(x, y) { var = deparse(substitute(y)); if(!deparse(substitute(y)) %in% names(x)) { stop('missing variable: ', var) }; x[[var]] }
#> prob1<,2,3),c(5,4,3)))
#> colnames(prob1)<-c("Education","Ethnicity")
#> table(prob1$Eduction, prob1$Ethnicity)
# Error in prob1$Eduction : wrong name: Eduction
# error when nrow is used on non data.frames or matrices
nrow <- function(x) { if ( || is.matrix(x)) { dim(x)[1L] } else { stop("nrow cannot be used on ", type(x)) } }
jimhester / linux.txt
Last active August 29, 2015 14:20
Windows LDFLAGS error
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/aes.c -o src/aes.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/crc32.c -o src/crc32.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/digest.c -o src/digest.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/init.c -o src/init.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/md5.c -o src/md5.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/pmurhash.c -o src/pmurhash.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/raes.c -o src/raes.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O0 -fprofile-arcs -ftest-coverage -c src/sha1.c -o src/sha1.o
gcc -std=gnu99
R Under development (unstable) (2015-05-13 r68364) -- "Unsuffered Consequences"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
jimhester / appveyor.yml
Created June 2, 2015 12:35
Example appveyor YML for Bioconductor package
# DO NOT CHANGE the "init" and "install" sections below
# Download script file from GitHub
ps: |
$ErrorActionPreference = "Stop"
Invoke-WebRequest -OutFile "..\appveyor-tool.ps1"
Import-Module '..\appveyor-tool.ps1'
a <- sample(letters, 1e6, TRUE)
b <- as.factor(a)
microbenchmark(c <- a[a == "d"],
d <- b[b == "d"],
e <- {
mtch <- match("d", levels(b))
b[as.integer(b) == mtch]
date <- "2015-04-17"
tmp <- tempfile()
args = c("log",
"-r", sprintf("{%s}:HEAD", date),
stdout = tmp)