Skip to content

Instantly share code, notes, and snippets.

@hadley
Created August 3, 2012 16:51
Show Gist options
  • Save hadley/3249435 to your computer and use it in GitHub Desktop.
Save hadley/3249435 to your computer and use it in GitHub Desktop.
vertoccurrence <- function(key="r_B68F3", grp="fish", t = NULL, l = NULL,
c = NULL, d = NULL, q = NULL, p = NULL, m = NULL, cols = NULL, num = NULL,
set = NULL)
{
grp <- match.arg(grp, c("bird", "herp", "fish"))
url <- c(
bird = "http://ornis2.ornisnet.org/api/v1/occurrence/?",
herp = "http://herpnet2.org/api/v1/occurrence/?",
fish = "http://www.fishnet2.net/api/v1/occurrence/?"
)[grp]
query <- URLencode(c(api = key, t = t, l = l, c = c, d = d, q = q, p = p,
m = m, cols = cols, num = num, set = set))
qstr <- paste(names(query), "=", query, sep = "&")
qurl <- paste(url, qstr, sep = "")
out <- read.csv(qurl)
if (nrow(out) == 0){
out <- NULL
message("No records found")
}
out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment