Skip to content

Instantly share code, notes, and snippets.

@sckott
sckott / rfna_demo.r
Created January 27, 2012 19:02
Demo of using rnfa R package to scrape trait data - in this example for receptacle traits.
# A web page with taxa names you want to get trait data from
pg1 <- 'http://www.efloras.org/browse.aspx?flora_id=1&start_taxon_id=10074&page=1'
# Get the daughter URLs from the taxa on the page, using doMC to speed things up
urls <- getdaughterURLs(pg1, cores=TRUE, no_cores=2)
|======================================================================================================| 100%
# Get the receptacle trait state for the taxa
@sckott
sckott / mvabund.r
Created March 19, 2012 13:29
playing with mvabund
#### mvabund play
# install mvabund from CRAN pkg repository
install.packages("mvabund")
require(mvabund)
# plot abundance by copepod species
data(Tasmania)
attach(Tasmania)
tasmvabund <- mvabund(Tasmania$copepods)
plot(tasmvabund ~ treatment, col = as.numeric(block))
@sckott
sckott / ggplot2SEM.R
Created May 1, 2012 05:23 — forked from emhart/ggplot2SEM.R
ggplot2 SEM model example
require(ggplot2); require(gridExtra)
###Generate box coords
###A function to generat a blank box for use with geom_path()
box_coords <- function(x,y,size){
b.x <- c(rep(x,2) - (size[1] / 2),rep(x,2) + (size[1] / 2))
b.x[5] <- b.x[1]
b.y <- c(y-(size[2] / 2),rep(y,2)+(size[2] / 2),y-(size[2] / 2))
b.y[5] <- b.y[1]
rmat <- data.frame(cbind(b.x,b.y))
@sckott
sckott / getgithubstats.r
Created May 5, 2012 13:29
Get github stats (forks and watchers) on user or organization account.
# Store a function with man lines
# Go Here: http://beta.opencpu.org/apps/opencpu.demo/storefunction/
# number: x3e50ee0780
# link: http://beta.opencpu.org/R/call/store:tmp/x3e50ee0780/png?id='ropensci'&type='org'
the <- function (id = 'hadley', type = 'user')
{
require(RCurl); require(RJSONIO); require(ggplot2); require(reshape2); require(plyr)
if(type == 'user'){ url = "https://api.github.com/users/" } else
if(type == 'org'){ url = "https://api.github.com/orgs/" } else
stop("parameter 'type' has to be either 'user' or 'org' ")
@sckott
sckott / firstgitdeskpresentation
Created July 5, 2012 19:42
my first gistdeck presentation
# my first gistdeck presentation
## This is fun
* [this is a link to my home page](http://schamberlain.github.com/scott)
* [and my blog](http://schamberlain.github.com/blog.html)
* yeah links
@sckott
sckott / Markdown.md
Created July 5, 2012 19:43
my first gistdeck presentation
@sckott
sckott / Markdown.md
Created July 5, 2012 19:44
my first gistdeck presentation
@sckott
sckott / getURL_v_GET.r
Created July 5, 2012 23:01
getURL vs. GET
library(httr); library(plyr); require(RCurl)
stackexchange_GET <- function(ids, url = "https://api.stackexchange.com/2.0/users/")
{
res <- GET(paste0(url, ids), query = list(site = "stackoverflow"))
json <- parsed_content(res)
json
}
stackexchange_getURL <- function(ids, url = "https://api.stackexchange.com/2.0/users/")
{
@sckott
sckott / apistatus.r
Created August 23, 2012 17:09
Check status of APIs used in rOpenSci libraries.
apistatus <- function() {
require(RCurl); require(RJSONIO); require(ggplot2); require(XML)
# PLoS search API
if(identical(
RJSONIO::fromJSON(RCurl::getURL(
"http://api.plos.org/search?q=id:10.1371/journal.pbio.0000012&wt=json"))$response$docs[[1]]$eissn,
"1545-7885") == TRUE){plos_search_api <- 1} else
{plos_search_api <- 0}
@sckott
sckott / matricesfromabddist.r
Created August 28, 2012 00:27
Make network matrices from abundance distributions and calculate network structures
#######################################################
###########Community-Network Structure Simulation######
#######################################################
library(bipartite)
# Set of mean and sd combinations of log-normal distribution
mu<-c(0.5,2.9,5.3)
sig<-c(0.75,1.6,2.45)
make.matrices<-function(a,b,nmats){