Permalink
Browse files

added fxn namesearch

  • Loading branch information...
1 parent d0757c7 commit 7b2ccc0b7167772a31bfffdc0f24883a0b7dd87b @sckott sckott committed Sep 5, 2011
Showing with 40 additions and 1 deletion.
  1. +1 −1 R/GetItemByIdentifier.R
  2. +39 −0 R/namesearch.R
View
@@ -6,7 +6,7 @@ GetItemByIdentifier <-
# value: the identifier value (character)
# format: json or xml (character)
# Examples:
-# GetItemByIdentifier('ia', 'animalkingdomarr03cuvi', 'xml')
+# GetItemByIdentifier('ia', 'animalkingdomarr03cuvi', 'json')
function(type = NA, value = NA, format = NA,
url = 'http://www.biodiversitylibrary.org/api2/httpquery.ashx',
View
@@ -0,0 +1,39 @@
+# namesearch.R
+
+namesearch <-
+# Args:
+# species: species name (character)
+# format: json or xml (character)
+# Examples:
+# namesearch(species = "poa annua", format = "json")
+# namesearch(species = "helianthus annuus", format = "json")
+
+function(species = NA, format = NA,
+ method = 'NameSearch',
+ url = 'http://www.biodiversitylibrary.org/api2/httpquery.ashx',
+ key = getOption("BioHerLibKey", stop("need an API key for the Biod Her Library")),
+ ...,
+ curl = getCurlHandle())
+{
+# args <- list(op = 'NameSearch', apikey = key)
+# if(!is.na(species))
+# args$name <- gsub(" ", "+", species)
+# if(!is.na(format))
+# args$format <- format
+ speciess <- gsub(" ", "+", species)
+ url2 <- paste(url, "?op=", method, "&name=", speciess, "&apikey=", key, "&format=", format, sep = "")
+ tt <- getURLContent(url2)
+# tt <- getForm(url,
+# .params = args,
+# ...,
+# curl = curl)
+ if(format == 'json') {outprod <- fromJSON(I(tt))} else
+ if(format == 'xml') {outprod <- xmlTreeParse(I(tt))}
+ getit <- function(x) {
+ if(is.null(x[[1]]) == TRUE) x[[1]] <- paste("nonamebankID")
+ t(ldply(x))[2,]
+ }
+ outdf <- ldply(outprod[3][[1]], getit)
+ names(outdf) <- c("NameBankID", "NameConfirmed")
+ return(outdf)
+}

0 comments on commit 7b2ccc0

Please sign in to comment.