Skip to content

Instantly share code, notes, and snippets.

View sckott's full-sized avatar
😸

Scott Chamberlain sckott

😸
View GitHub Profile
@sckott
sckott / rplos_alm3.r
Created November 1, 2012 16:57
Plos ALM API v3 example
install.packages("devtools")
require(devtools)
install_github("rplos", "rOpenSci", "almv3")
require(rplos)
out <- almplosallviews(doi='10.1371/journal.pmed.0050201', info='detail')
almplotallviews(out, type="totalmetrics")
almplotallviews(out, type="history")
@sckott
sckott / iplant_tnrastic.r
Created November 6, 2012 16:22
phylotastic TNRS matching function, not working, getting errors on API calls.
#' Search the Phylotastic Taxonomic Name Resolution Service
#'
#' Match taxonomic names using the Taxonomic Name Resolution Service (TNRS).
#' Returns score of the matched name, and whether it was accepted or not.
#'
#' @import RCurl XML plyr stringr RJSONIO
#' @param query Quoted taxonomic names to search in a vector (character).
#' @param output 'all' for raw list output or 'names' for matched names
#' and their match scores, plus plant family names (character).
#' @param sleep Numer of seconds by which to pause by before retrieving the
@sckott
sckott / plos_altmetrics.r
Created November 6, 2012 19:40
Get altmetrics data on PLoS papers in R.
## This gist is an example of getting altmetrics data on PLoS papers.
## In a nutshell, this script reads in a list of DOIs provided by Martin Fenner of PLoS, and gets the historical altmetrics
## data on each DOI, and writes it to a txt file. You can do lots of things with this data. How do different altmetrics
## relate to one another within a paper, across papers, how do they vary through time for a paper, etc.
## I ran this in an EC2 using an m2.2xlarge instance.
## It took about XX to run.
## The resulting file was about XXX mb.
library(devtools)
install_github('rplos', 'ropensci', 'almv3')
@sckott
sckott / compare_evol_models.r
Created November 6, 2012 19:52
Visual comparison of trait evol models.
require(ggplot2); require(reshape2); require(grid); library(gsl); library(wrightscape)
theme_set(theme_bw())
plot.path_sim <- function(x, ...) ggplot(x) + geom_line(aes(time,
value, group = rep), alpha = 0.05)
reps <- 500
X <- bm_path_sim(reps = reps)
Y <- ou_path_sim(reps = reps, alpha = 6)
W <- brownie_path_sim(reps = reps, sigma = 0.3, sigma2 = 1.2, release_frac = 0.7) # has 1/release_frac time = 2
px <- plot.path_sim(X) + opts(title = "Brownian Motion") +
coord_cartesian(ylim = c(-2, 2)) + ylab("trait value")
@sckott
sckott / ropensci_dependencies.r
Created November 7, 2012 18:42
Data.frame of dependencies and reverse dependencies on rOpenSci packages.
install.packages("packdep")
library(packdep)
d <- map.depends()
dat <- dependencies(d)
row.names(dat) <- NULL
dat[dat$package %in% c("rgbif","rfigshare","rplos","ropensnp","ritis","rentrez","rebird","treebase","RMendeley","rfishbase"), ]
## Output on 07-Nov-12
> dat[dat$package %in% c("rgbif","rfigshare","rplos","ropensnp","ritis","rentrez","rebird","treebase","RMendeley","rfishbase"), ]
@sckott
sckott / namingvectors.r
Created November 14, 2012 06:00
named vectors
myvector <- c(1,2,3) # create a vector (numbers in this case)
myvector # look at it, it doesn't have names, but we can add them
names(myvector) # there are no names on the elements of the vector
names(myvector) <- c("a","b","c") # doing "names(object) <- X" names the elements of the vector
myvector # now each element has a name in the vector
myvector[["a"]] # we can call each element by its name if want to now, or by doing
myvector["a"]
@sckott
sckott / orcid_pubs_eg.r
Created November 19, 2012 03:16
How do we parse this into pretty citations? And probably use those bibtext like citations too?
> temp <- getURL("http://pub.orcid.org/0000-0002-9341-7985/orcid-works")
> xmlParse(temp)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<orcid-message xmlns="http://www.orcid.org/ns/orcid">
<message-version>1.0.7</message-version>
<orcid-profile type="user">
<orcid>0000-0002-9341-7985</orcid>
<orcid-history>
<creation-method>website</creation-method>
<completion-date>2012-10-16T13:08:32.715+01:00</completion-date>
@sckott
sckott / is.invasive.R
Created November 26, 2012 17:02 — forked from ibartomeus/is.invasive.R
This function check which species (both plants and animals) are considered "invaders" somewhere in the world.
is.invasive()
##Description##
#This function check which species (both plants and animals) are considered "invaders" somewhere in the
# world. For that end, it checks GISD (http://www.issg.org/database/welcome/) and returns a value, either
#"Not invasive" or the brief description presented in GISD. Note that the webpage contains more
#information. Also note that the function won't tell you if it's exotic in your area, a lot of exotic
#species are not considered invaders (yet). As expected, the function is as good as the database is, which
#I find quite reliable and well maintained. The database is also able to recognize a lot (but not all) of
@sckott
sckott / modeltodf.r
Created November 29, 2012 00:32
model to data.frame
#
library(plyr)
m1 <- lm(Petal.Length ~ Petal.Width, data=iris)
m2 <- lm(Petal.Length ~ Petal.Width + Species, data=iris)
tt <- function(x) {
temp <- data.frame(rnorm(1), summary(x)[4], summary(x)[8])
names(temp) <- c("model", "est", "se", "t", "p", "r2")
temp
}
@sckott
sckott / wordcloud.r
Created November 30, 2012 18:03
wordcloud
install.packages("wordcloud")
library(wordcloud)
wordcloud(
"Many years ago the great British explorer George Mallory, who
was to die on Mount Everest, was asked why did he want to climb
it. He said, \"Because it is there.\"
Well, space is there, and we’re going to climb it, and the
moon and the planets are there, and new hopes for knowledge
and peace are there. And, therefore, as we set sail we ask