Skip to content

Instantly share code, notes, and snippets.

[1] pry(main)> require 'alan'
LoadError: cannot load such file -- alan
from /Users/sacmac/.rbenv/versions/2.2.0-dev/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'

Using taxize to get a classification

Install taxize

install.packages("taxize")

Load taxize

@sckott
sckott / parse_error_messages.md
Last active August 29, 2015 13:56
Is there a general solution for parsing server error messages that aren't returned in the header in httr so that we can print error message for users in a package?

This is a call to the GBIF API. There is an intential error in the call that gives an error message from the server

com.spatial4j.core.exception.InvalidShapeException: Invalid latitude: latitudes are range -90 to 90: provided lat: [-125.0]

In R with httr:

library(httr)
call <- "http://api.gbif.org/v0.9/occurrence/search?geometry=POLYGON((38.4 -125, 40.9 -125, 40.9 -121.8, 38.4 -121.8, 38.4 -125))"
a &lt;- GET(call)

taxize integration: Pass in taxonomic identifiers

library(taxize)
library(spocc)

Via get_ids

@sckott
sckott / my.geojson
Created February 20, 2014 02:13
Occurrences of three bird species mapped
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sckott
sckott / crossref_alm.md
Created February 24, 2014 17:15
Get alm data for DOIs via Crossref using the alm R package

load alm

library(alm)

Define vector of DOIs, and search

Remember to get your api key, pass it in in the key parameter. Notice that we are passing the base url for the Crossref API, whereas the default is for the PLOS url http://alm.plos.org/api/v3/articles

install_github("ropengov/rsunlight")
library(rsunlight)
dream <- lapply(c('D','R'), function(x) cw_timeseries(phrase='i have a dream', party=x, start_date='1996-01-01', end_date='2013-01-01', granularity='month'))
df <- merge(dream[[1]], dream[[2]], by='month', all=TRUE)
df[is.na(df)] <- 0
names(df) <- c('date','D','R')
df$date <- as.character(df$date)
library(rCharts)
m1 &lt;- mPlot(x = "date", y = c("D", "R"), type = "Line", data = df)
@sckott
sckott / abiesmagmap.geojson
Created February 24, 2014 22:16
Abies magnifica polygons
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Install taxize

install.packages("taxize")

Load taxize

library(taxize)
@sckott
sckott / mapgrammar.md
Created March 1, 2014 00:00
Possible map grammar workflow

Possible unified workflow for making maps with species names or identifiers as a starting point, with map as output.

species | speciesids %>%
	getdata %>% # occ(), occ_search()
	cleandata %>% # fixnames(), removeimposslatlongvals(), 
	datatransformation %>% # 
	baselayer %>% # "osmaps", "", etc.
	maptype %>% # "bubble", "choropleth", etc.
	annotations %&gt;% # tooltips(), symbols(), legend()