Skip to content

Instantly share code, notes, and snippets.

@noamross
noamross / gist:5447008
Created April 23, 2013 20:14
proftable(), and improved summaryRprof() for code profiling in R
proftable <- function(file, lines=20) {
require(plyr)
sample.interval <- as.numeric(strsplit(readLines(file, 1), "=")[[1L]][2L])/1e+06
profdata <- as.matrix(read.table(file, header=FALSE, sep=" ", colClasses="character", skip=1, fill=TRUE, na.strings=""))
total.time <- nrow(profdata)*sample.interval
stacktable <- data.frame(table(aaply(profdata, 1, function(x) paste(rev(na.omit(x)), collapse=" > "))))
names(stacktable) <- c("Stack","PctTime")
stacktable$PctTime <- 100*stacktable$PctTime/nrow(profdata)
stacktable <- stacktable[order(stacktable$PctTime, decreasing=TRUE), c("PctTime", "Stack")]
rownames(stacktable) <- NULL
@noamross
noamross / formatting plots for pubs.R
Created November 21, 2013 05:18
Code from presentation to Davis R Users's group by Rosemary Hartman, November 20, 2013, on formatting plots for publication.
#'% How to format plots for publication using `ggplot2` (with some help from Inkscape)
#'% Rosemary Hartman
#'% 13-11-20 19:51:47
#'
#' ***The following is the code from a presentation made by Rosemary Hartman to
#' the [Davis R Users' Group](http://www.noamross.net/davis-r-users-group.html).
#' I've run the code through the `spin` function in `knitr` to produce this post.
#' Download the script to walk through [here](https://gist.github.com/noamross/7576436)***
#'
#' First, make your plot. I am going to use the data already in R
@noamross
noamross / dixondates.R
Last active November 23, 2018 08:22
Using times and dates in R
#'% Using Dates and Times in R
#'% Bonnie Dixon
#'% 14-02-10 15:09:57
#'
#' *Today at the [Davis R Users'
#' Group](http://www.noamross.net/davis-r-users-group.html), [Bonnie
#' Dixon](http://ffhi.ucdavis.edu/people/directory/bmdixon) gave a tutorial on the
#' various ways to handle dates and times in R. Bonnie provided this great script
#' which walks through essential classes, functions, and packages. Here it is piped through
#' `knitr::spin`. The original R script can be found as a gist
@noamross
noamross / vectorizationtalk.md
Created April 14, 2014 23:51
Rough draft of post on vectorization.

% Vectorization without Condescension % Noam Ross % 14-04-07 09:09:18

Here are my notes from a recent talk I gave on vectorization at a Davis R Users' Group meeting. Thanks to Vince Buffalo, John Myles White, and Hadley Wickham for their input as I was preparing this.

Beginning R users are often told to "vectorize" their code. Here, I try to explain why vectorization can be advantageous in R by showing how R works under the hood.

Now, remember, premature optimization is the root of all evil (Knuth). Don't start re-writing your code unless the time saved is going to be worth the time invested. Other approaches, like finding a bigger machine or parallelization, could give you more bang for the buck in terms of programming time. But if you und

@noamross
noamross / get_peerj_subject_dois.R
Created June 12, 2014 11:54
Grab DOIs of all PeerJ articles from a subject area
#Get DOIs for subject area from PeerJ
library(httr)
library(plyr)
#JSON for Ecology articles (paginated):
ecol_url = "https://peerj.com/articles/index.json?subject=1100"
dois = list()
repeat {
@noamross
noamross / slowGET.R
Created June 26, 2014 20:15
slowGET - A throttled version of GET
throttle = new.env(parent = emptyenv())
throttle$recent = data.frame(domain = character(), last_visit = character())
#' A throttled version of GET
#'
#' This uses \code{httr::GET} to fetch a web page, but throttles based on domains.
#'
#' \code{slowGET} keeps a list of domains recently accessed by itself in a
#' separate environment. If a domain has been accessed since \code{pause}
#' seconds ago, it will delay execution until that time has passed
@noamross
noamross / tutor.md
Last active August 29, 2015 14:12
Visually Impaired Bioinformatics Graduate Student Seeking R Programming Tutoring

I received the following inquiry from Thomas Hahn, a visually impaired graduate student seeking an R programming tutor. Anyone interested in working with Thomas can contact him at Thomas.F.Hahn2@gmail.com.

I am a visually impaired bioinformatics graduate student using microarray data for my master’s thesis aimed at deciphering the mechanism by which the yeast wild type can suppress the rise of free reactive oxygen species (ROS) induced by caloric restriction (CR) but the Atg15 and Erg6 knockout mutant cannot.

Since my remaining vision is very limited I need very high magnification. But that makes my visual field very small. Therefore I need somebody to guide me remotely through the R environment and teach me how to best use the R packages for bioinformatics, especially for microarray analysis, next generation sequencing and constructing gene and pathway interaction networks. This is very difficult for me to figure out without as

@noamross
noamross / msl_ama.md
Last active August 29, 2015 14:16
Draft MSL AMA blog post

We Run Scientific Computing Communities, Ask Us Anything

How do you create and nurture communities of people who teach, learn, and collaborate to build scientific computing skills? That's a question central to much of MSL's work, especially as we embark on new long-term training initiatives.

On March 24, 6-8PM EST, we're hosting an online panel discussion on this topic on our forum. It's Ask-Us-Anything, MSL-style. We want to spur knowledge-sharing among those who facilitate local learning communities. Are you part of a study group, users' group, or other community of people who help each other with these skills? Do you want to start one or improve how yours works? Please join us!

Our panelists each work on local initiatives to train computing skills and build learning communities. We'll be talking about our models, approaches, and challenges, and taking questions and comments about how to build such communities el

@noamross
noamross / google_wordcloud.R
Created April 22, 2015 01:13
Create a wordcloud of your google search history
# Script to make a word cloud of your google searches. Get your google search
# history at http://history.google.com. This script assumes the JSON files
# exported are in a 'Searches' subfolder
library(jsonlite)
library(rlist)
library(magrittr)
library(stringi)
library(wordcloud)
library(tm)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.