[med-svn] [r-cran-natserv] 03/05: New upstream version 0.1.4

Andreas Tille tille at debian.org
Mon Oct 2 10:12:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository r-cran-natserv.

commit 9271492004f8d86eb10a20274c0aeddad3f4e3a4
Author: Andreas Tille <tille at debian.org>
Date:   Mon Oct 2 12:08:47 2017 +0200

    New upstream version 0.1.4
---
 DESCRIPTION                       |  26 ++++++
 LICENSE                           |   2 +
 MD5                               |  27 ++++++
 NAMESPACE                         |   8 ++
 NEWS.md                           |  15 ++++
 R/globals.R                       |   6 ++
 R/http.R                          |   6 ++
 R/natserv-package.R               |  20 +++++
 R/ns_data.R                       | 172 ++++++++++++++++++++++++++++++++++++++
 R/ns_images.R                     |  89 ++++++++++++++++++++
 R/ns_map.R                        | 147 ++++++++++++++++++++++++++++++++
 R/ns_search.R                     |  40 +++++++++
 R/zzz.R                           |  71 ++++++++++++++++
 README.md                         | 127 ++++++++++++++++++++++++++++
 data/sysdata.rda                  | Bin 0 -> 731 bytes
 debian/README.test                |   8 --
 debian/changelog                  |   5 --
 debian/compat                     |   1 -
 debian/control                    |  28 -------
 debian/copyright                  |  32 -------
 debian/docs                       |   3 -
 debian/rules                      |   5 --
 debian/source/format              |   1 -
 debian/tests/control              |   5 --
 debian/tests/run-unit-test        |  17 ----
 debian/watch                      |   2 -
 man/nat_states.Rd                 |  14 ++++
 man/natserv-package.Rd            |  15 ++++
 man/ns_data.Rd                    | 120 ++++++++++++++++++++++++++
 man/ns_images.Rd                  | 101 ++++++++++++++++++++++
 man/ns_map.Rd                     |  39 +++++++++
 man/ns_search.Rd                  |  59 +++++++++++++
 tests/test-all.R                  |   2 +
 tests/testthat/helper_data.R      |   1 +
 tests/testthat/ns_data_output.rda | Bin 0 -> 21148 bytes
 tests/testthat/test-ns_data.R     |  14 ++++
 tests/testthat/test-ns_images.R   |  14 ++++
 tests/testthat/test-ns_map.R      |  47 +++++++++++
 tests/testthat/test-ns_search.R   |  15 ++++
 39 files changed, 1197 insertions(+), 107 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..c01e4ca
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,26 @@
+Package: natserv
+Title: 'NatureServe' Interface
+Description: Interface to 'NatureServe' (<http://www.natureserve.org>).
+    Includes methods to get data, image metadata, search taxonomic names,
+    and make maps.
+Version: 0.1.4
+License: MIT + file LICENSE
+URL: https://github.com/ropensci/natserv
+BugReports: https://github.com/ropensci/natserv/issues
+Encoding: UTF-8
+Authors at R: c(
+    person("Scott", "Chamberlain", role = c("aut", "cre"),
+    email = "myrmecocystus at gmail.com")
+  )
+LazyData: true
+Depends: R(>= 3.2.1)
+Imports: crul (>= 0.2.0), xml2 (>= 1.0.0), tibble (>= 1.2), data.table
+        (>= 1.10.0)
+Suggests: roxygen2 (>= 5.0.1), testthat, covr, ggplot2, maps, mapproj
+RoxygenNote: 5.0.1
+NeedsCompilation: no
+Packaged: 2017-01-03 20:21:45 UTC; sacmac
+Author: Scott Chamberlain [aut, cre]
+Maintainer: Scott Chamberlain <myrmecocystus at gmail.com>
+Repository: CRAN
+Date/Publication: 2017-01-03 23:58:07
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..37ee2c7
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,2 @@
+YEAR: 2017
+COPYRIGHT HOLDER: Scott Chamberlain
diff --git a/MD5 b/MD5
new file mode 100644
index 0000000..3eca20d
--- /dev/null
+++ b/MD5
@@ -0,0 +1,27 @@
+f5f61a30ce3ca67d45756bec1ab073f5 *DESCRIPTION
+c5af52351472a750055a760a8924ce71 *LICENSE
+95891222e0c73937cc2f4e41e6fb3c89 *NAMESPACE
+55d9a6e04b2fb5d9e195fc117605d2ec *NEWS.md
+9495e27eac4003c7cbeb500f51982d76 *R/globals.R
+7c5158c1f3f32fcf7f277ae34f9bc064 *R/http.R
+9d862aa5d6bc492763166c200d790d62 *R/natserv-package.R
+f3a0bad7c1f71c31b0435823c457bf63 *R/ns_data.R
+fcae557ac1bac977ca5a7985be1d4e42 *R/ns_images.R
+a54054d2e082de8c0906173633a5d99e *R/ns_map.R
+9b5174f7ea23f5fda3c9199ffd844c3b *R/ns_search.R
+e75f3a71797832e9c92ca382db76035a *R/zzz.R
+69465a767c750f89afeccfaf9663737f *README.md
+4b1a9d05899601061c9c77559b355ea6 *data/sysdata.rda
+e0f5b1997e7b37e4444b4603150f9b22 *man/nat_states.Rd
+946920a25da2a49ade87057708a8f883 *man/natserv-package.Rd
+ba925986edf4dd3ab432cd2a8dccaadd *man/ns_data.Rd
+9fc361745d3bb5de101bbc81cf4318f0 *man/ns_images.Rd
+98ae9db0928eb0f505ba762164a476f4 *man/ns_map.Rd
+922a5f9626ac2935602c76e7b393862e *man/ns_search.Rd
+70d22cd63830907bbd3db9fa195924dc *tests/test-all.R
+7ef013470727c0e7ea5f18993953bce4 *tests/testthat/helper_data.R
+17813e1b13ac49fa3065034831296db9 *tests/testthat/ns_data_output.rda
+a12932c33971aacc3fde712b09ed8b6d *tests/testthat/test-ns_data.R
+20a5203ae389c0371f41b19a3ca6038d *tests/testthat/test-ns_images.R
+fb3c18a8a647223b13803c43ee636e54 *tests/testthat/test-ns_map.R
+31a2c4e8d6eddc3bd2d7a987adb34144 *tests/testthat/test-ns_search.R
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..ddbf1fd
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,8 @@
+# Generated by roxygen2: do not edit by hand
+
+export(ns_data)
+export(ns_images)
+export(ns_map_cons)
+export(ns_map_county)
+export(ns_map_stpr)
+export(ns_search)
diff --git a/NEWS.md b/NEWS.md
new file mode 100644
index 0000000..30686f3
--- /dev/null
+++ b/NEWS.md
@@ -0,0 +1,15 @@
+natserv 0.1.4
+=============
+
+### MINOR IMPROVEMENTS
+
+* `natserv` now requires `crul` `>= 0.2.0`, which fixed URL encoding
+to make our work in `natserv` easier.
+
+
+natserv 0.1.0
+=============
+
+### NEW FEATURES
+
+* released to CRAN
diff --git a/R/globals.R b/R/globals.R
new file mode 100644
index 0000000..6f07223
--- /dev/null
+++ b/R/globals.R
@@ -0,0 +1,6 @@
+if (base::getRversion() >= "2.15.1") {
+  utils::globalVariables(
+    c("currentPresenceAbsence", "element_blank", "group", "lat", "long",
+    "speciesOccurrenceCount", "theme", "unit", "nat_states")
+  )
+}
diff --git a/R/http.R b/R/http.R
new file mode 100644
index 0000000..c59a571
--- /dev/null
+++ b/R/http.R
@@ -0,0 +1,6 @@
+ns_GET <- function(url, query, ...){
+  cli <- crul::HttpClient$new(url = url, opts = list(...))
+  temp <- cli$get(query = query)
+  temp$raise_for_status()
+  temp$parse("UTF-8")
+}
diff --git a/R/natserv-package.R b/R/natserv-package.R
new file mode 100644
index 0000000..1f0e905
--- /dev/null
+++ b/R/natserv-package.R
@@ -0,0 +1,20 @@
+#' natserv
+#'
+#' @name natserv-package
+#' @aliases natserv
+#' @docType package
+#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
+#' @keywords package
+NULL
+
+#' A data.frame with 49 rows and 2 columns
+#'
+#' \itemize{
+#'   \item state (character) state 2 letter abbreviation
+#'   \item state_name (character) state full name
+#' }
+#'
+#' @name nat_states
+#' @docType data
+#' @keywords data
+NULL
diff --git a/R/ns_data.R b/R/ns_data.R
new file mode 100644
index 0000000..f4cca7b
--- /dev/null
+++ b/R/ns_data.R
@@ -0,0 +1,172 @@
+#' NatureServe data
+#'
+#' @export
+#' @template ns
+#' @param uid (character) a species UID, e.g., ELEMENT_GLOBAL.2.100925
+#' @template status
+#'
+#' @return a named list, with possible slots:
+#' \itemize{
+#'  \item natureserve_uri
+#'  \item classification
+#'  \item economicAttributes
+#'  \item license
+#'  \item references
+#'  \item conservationStatus
+#'  \item managementSummary
+#'  \item distribution
+#' }
+#'
+#' @examples \dontrun{
+#' ## single id
+#' (res <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925'))
+#' ## many ids at once
+#' res <- ns_data(uid = c('ELEMENT_GLOBAL.2.100925', 'ELEMENT_GLOBAL.2.104470'))
+#' res$ELEMENT_GLOBAL.2.100925
+#' res$ELEMENT_GLOBAL.2.104470
+#' }
+ns_data <- function(uid, key = NULL, ...) {
+  res <- ns_GET(
+    url = paste0(ns_base(), '/v1.1/globalSpecies/comprehensive'),
+    query = list(
+      uid = paste0(uid, collapse = ","),
+      NSAccessKeyId = check_key(key)),
+    ...
+  )
+  xml <- xml2::read_xml(res, encoding = "UTF-8")
+  xml <- xml2::xml_children(xml)
+  stats::setNames(lapply(xml, function(m) {
+    nsuri <- xml2::xml_text(xml2::xml_find_first(m, ".//d1:natureServeExplorerURI"))
+    class <- xml2::as_list(xml2::xml_find_first(m, ".//d1:classification"))
+    ecostat <- xml2::xml_text(xml2::xml_find_first(m, ".//d1:economicAttributes"))
+    license <- strtrim(xml2::xml_text(xml2::xml_find_first(m, ".//d1:license")))
+    refs <- xml2::xml_text(xml2::xml_children(xml2::xml_find_first(m, "//d1:references")))
+    constat <- xml2::xml_find_first(m, ".//d1:conservationStatus")
+    constat_c <- xml2::xml_children(xml2::xml_find_first(constat, './/d1:otherStatuses'))
+    constat_other <- stats::setNames(lapply(constat_c, function(z) {
+      sapply(xml2::xml_children(z), function(x)
+        as.list(stats::setNames(xml2::xml_text(x), xml2::xml_name(x))))
+    }), xml2::xml_attr(constat_c, "name"))
+    constat_ns <- parse_nss(xml2::xml_find_first(constat, './/d1:natureServeStatus'))
+    ms <- as_list_(xml2::xml_find_first(m, ".//d1:managementSummary"))
+    dist <- parse_dist(xml2::xml_find_first(m, ".//d1:distribution"))
+    list(
+      uid = xml2::xml_attr(m, "uid"),
+      speciesCode = xml2::xml_attr(m, "speciesCode"),
+      natureserve_uri = nsuri,
+      classification = class,
+      economicAttributes = ecostat,
+      license = license,
+      references = refs,
+      conservationStatus = list(other = constat_other, natureserve = constat_ns),
+      managementSummary = ms,
+      distribution = dist
+    )
+  }), uid)
+}
+
+# parsers
+parse_dist <- function(x) {
+  tmp <- xml2::xml_children(x)
+  list(
+    conservationStatusMap = xml2::xml_text(which_name(tmp, "conservationStatusMap")),
+    globalRange = parse_if_1(tmp, "globalRange"),
+    rangeMap = xml2::xml_text(which_name(tmp, "rangeMap")),
+    endemism = parse_if_1(tmp, "endemism"),
+    nations = {
+      ch <- xml2::xml_children(which_name(tmp, "nations"))
+      stats::setNames(lapply(ch, function(z) {
+        if (xml2::xml_length(z) == 0) {
+          list()
+        } else {
+          list(
+            nationalDistributions = {
+              as_list_(xml2::xml_child(which_name(xml2::xml_children(z), "nationalDistributions")[[1]]))
+            },
+            subnations = {
+              kids <- xml2::xml_children(which_name(xml2::xml_children(z), "subnations")[[1]])
+              lapply(kids, function(z) {
+                c(
+                  as.list(xml2::xml_attrs(z)),
+                  as_list_(xml2::xml_find_first(z, "//d1:subnationalDistribution"))
+                )
+              })
+            }
+          )
+        }
+      }), xml2::xml_attr(ch, "nationCode"))
+    },
+    watersheds = {
+      ch <- xml2::xml_children(which_name(tmp, "watersheds"))
+      tibble::as_data_frame(data.table::rbindlist(lapply(xml2::xml_children(ch), function(w) {
+        list(
+          type = xml2::xml_attr(w, "type"),
+          watershedName = xml2::xml_text(xml2::xml_find_first(w, "d1:watershedName")),
+          watershedCode = xml2::xml_text(xml2::xml_find_first(w, ".//d1:watershedCode")),
+          speciesOccurrenceCount = xml2::xml_text(xml2::xml_find_first(w, "d1:speciesOccurrenceCount"))
+        )
+      }), use.names = TRUE, fill = TRUE))
+    },
+    countyDistribution = {
+      ch <- xml2::xml_children(xml2::xml_find_first(which_name(tmp, "countyDistribution"), "d1:occurrenceNations"))
+      stats::setNames(lapply(ch, function(z) {
+        st <- xml2::xml_children(xml2::xml_find_first(z, "d1:occurrenceStates"))
+        stats::setNames(lapply(st, function(g) {
+          data.table::setDF(data.table::rbindlist(
+            lapply(xml2::xml_children(xml2::xml_find_first(g, "d1:occurrenceCounties")), as_list_),
+            fill = TRUE,
+            use.names = TRUE
+          ))
+        }), xml2::xml_attr(st, "code"))
+      }), xml2::xml_attr(ch, "code"))
+    }
+  )
+}
+
+parse_nss <- function(x) {
+  tmp <- xml2::xml_children(xml2::xml_find_first(x, "d1:globalStatus"))
+  list(
+    rank = xml2::xml_text(which_name(tmp, "rank")),
+    roundedRank = xml2::as_list(which_name(tmp, "roundedRank")[[1]]),
+    statusLastReviewed = xml2::xml_text(which_name(tmp, "statusLastReviewed")),
+    statusLastChanged = xml2::xml_text(which_name(tmp, "statusLastChanged")),
+    reasons = xml2::xml_text(which_name(tmp, "reasons")),
+    conservationStatusFactors = {
+      ch <- xml2::xml_children(which_name(tmp, "conservationStatusFactors"))
+      if (length(ch) == 0) {
+        list()
+      } else {
+        list(
+          globalAbundance = parse_if_1(ch, "globalAbundance"),
+          estimatedNumberOfOccurrences = parse_if_1(ch, "estimatedNumberOfOccurrences"),
+          globalShortTermTrend = xml2::xml_text(which_name(ch, "globalShortTermTrend")),
+          globalLongTermTrend = xml2::xml_text(which_name(ch, "globalLongTermTrend")),
+          globalProtection = parse_if_1(ch, "globalProtection"),
+          threat = xml2::xml_text(which_name(ch, "threat"))
+        )
+      }
+    },
+    nationalStatuses = {
+      ch <- xml2::xml_children(which_name(tmp, "nationalStatuses")[[1]])
+      stats::setNames(lapply(ch, function(w) {
+        w <- xml2::xml_children(w)
+        list(
+          rank = xml2::xml_text(which_name(w, "rank")),
+          roundedRank = xml2::xml_text(which_name(w, "roundedRank")),
+          statusLastReviewed = xml2::xml_text(which_name(w, "statusLastReviewed")),
+          subnationalStatuses = {
+            subst <- xml2::xml_children(which_name(w, "subnationalStatuses"))
+            lapply(subst, function(z) {
+              c(
+                as.list(xml2::xml_attrs(z)),
+                rank = xml2::xml_text(which_name(xml2::xml_children(z), "rank")),
+                roundedRank = xml2::xml_text(which_name(xml2::xml_children(z), "roundedRank"))
+              )
+            })
+          }
+        )
+      }), xml2::xml_attr(ch, "nationCode"))
+    }
+  )
+}
+
diff --git a/R/ns_images.R b/R/ns_images.R
new file mode 100644
index 0000000..94ab0b2
--- /dev/null
+++ b/R/ns_images.R
@@ -0,0 +1,89 @@
+#' NatureServe image metadata
+#'
+#' @export
+#' @template ns
+#' @param uid (character) a species UID, e.g., ELEMENT_GLOBAL.2.100925
+#' @param scientificName (character) An asterisk (*) wildcarded species
+#' scientific name, e.g., 'Aquila chry*'. Name matching is case-insensitive.
+#' @param commonName (character) An asterisk (*) wildcarded species common
+#' name, e.g., 'g*EAGLE'. Name matching is case-insensitive.
+#' @param includeSynonyms (character)	An optional parameter, relevant to
+#' scientific or common name queries, that indicates whether to include
+#' synonymous names in the query, as follows:
+#' \itemize{
+#'  \item Y (or y) - search the Primary and all synonymous Scientific and
+#'  Common Names
+#'  \item Any other value, or omitted - search only the Primary Scientific
+#'  and Common Name fields
+#' }
+#' @param resolution (character)	An optional parameter that restricts output
+#' to images at a certain resolution. The value can be of one of the following.
+#' \itemize{
+#'  \item lowest - return only the lowest resolution version of images
+#'  \item highest - return only the highest resolution version of images
+#'  \item thumbnail - return only the version NatureServe deems the
+#'  'thumbnail image'
+#'  \item web - return only the version NatureServe deems the 'web image'
+#' }
+#' The omission of this parameter leads to the return of metadata for images at
+#' all available resolutions.
+#' @param ITISNames (character)	An optional parameter, relevant to scientific
+#' or common name queries, that will indicate whether to restrict queries to
+#' ITIS names, as follows.
+#' \itemize{
+#'  \item Y (or y) - query using ITIS names
+#'  \item Any other value, or omitted - query using NatureServe names
+#' }
+#' NOTE: This parameter is a placeholder only and will not affect processing.
+#' At present, searching by ITIS names is not possible.
+#'
+#' @details Note that the NatureServer servers apparently want Windows
+#' HTML encoding (Windows-1252), instead of UTF-8, so some accents
+#' and such may not work
+#'
+#' @return a list with terms and images
+#'
+#' @examples \dontrun{
+#' # search by uid
+#' ns_images(uid = 'ELEMENT_GLOBAL.2.100925')
+#'
+#' # search by common name and resolutio thumbnail
+#' (res <- ns_images(commonName = "*eagle", resolution = 'thumbnail'))
+#'
+#' # search "Ruby*", all common names [in any language], and highest
+#' # resolution only:
+#' (res <- ns_images(commonName = "Ruby*", includeSynonyms = 'y',
+#'   resolution = 'highest'))
+#' }
+ns_images <- function(uid = NULL, scientificName = NULL, commonName = NULL,
+                      includeSynonyms = NULL, resolution = NULL,
+                      ITISNames = NULL, key = NULL, ...) {
+
+  args <- tc(list(uid = uid, scientificName = scientificName,
+                  commonName = commonName, includeSynonyms = includeSynonyms,
+                  resolution = resolution,
+                  ITISNames = ITISNames, NSAccessKeyId = check_key(key)))
+  res <- ns_GET(url = paste0(ns_base(), '/v1/globalSpecies/images'),
+                query = args, ...)
+  xml <- xml2::read_xml(res)
+  list(
+    terms = strtrim(xml2::xml_text(
+      xml2::xml_find_first(xml, "d1:termsAndConditions"))),
+    images = lapply(xml2::xml_find_all(xml, "d1:image"), function(w) {
+      d1 <- xml2::xml_find_all(w, "d1:*")
+      d1 <- d1[which(xml2::xml_name(d1) != "imagePermission")]
+      c(
+        sapply(d1, function(y) as.list(stats::setNames(xml2::xml_text(y),
+                                                       xml2::xml_name(y)))),
+        list(
+          imagePermission =
+            sapply(
+              xml2::xml_children((xml2::xml_find_all(w, "d1:imagePermission"))),
+              function(y) as.list(stats::setNames(xml2::xml_text(y),
+                                                  xml2::xml_name(y))))),
+        sapply(xml2::xml_find_all(w, "dc:*"), function(y)
+          as.list(stats::setNames(xml2::xml_text(y), xml2::xml_name(y))))
+      )
+    })
+  )
+}
diff --git a/R/ns_map.R b/R/ns_map.R
new file mode 100644
index 0000000..25f7531
--- /dev/null
+++ b/R/ns_map.R
@@ -0,0 +1,147 @@
+#' Map NatureServe data
+#'
+#' @export
+#' @name ns_map
+#' @param x the result of a call to \code{\link{ns_data}}
+#' @param ... ignored
+#' @examples \dontrun{
+#' # Aquila chrysaetos
+#' x <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+#' ns_map_county(x)
+#' ns_map_cons(x)
+#' ns_map_stpr(x)
+#'
+#' # Ursus americanus
+#' x <- ns_data('ELEMENT_GLOBAL.2.100661')
+#' ns_map_county(x)
+#' ns_map_cons(x)
+#' ns_map_stpr(x)
+#' }
+ns_map_county <- function(x, ...) {
+  chek_pk("mapproj")
+  chek_pk("ggplot2")
+  chek_pk("maps")
+  stopifnot(inherits(x, "list"))
+  co <- x[[1]]$distribution$countyDistribution
+  if (length(co) == 0) stop("no county distribution data", call. = FALSE)
+  co <- co[[1]]
+  co <- Map(function(x, y) {
+    x$state <- y
+    x
+  }, co, names(co))
+  dat <- data.table::setDF(
+    data.table::rbindlist(co, fill = TRUE, use.names = TRUE)
+  )
+  dat$countyName <- tolower(dat$countyName)
+  dat$maximumLastObservedYear <- as.numeric(dat$maximumLastObservedYear)
+  dat$speciesOccurrenceCount <- as.numeric(dat$speciesOccurrenceCount)
+
+  dat <- merge(dat, nat_states, by = "state")
+
+  counties <- ggplot2::map_data("county")
+  counties_plus <- merge(
+    counties,
+    dat,
+    by.x = c('region', 'subregion'),
+    by.y = c('state_name', 'countyName'),
+    all = TRUE)
+  counties_plus <- counties_plus[order(counties_plus$order),]
+  states <- ggplot2::map_data("state")
+  ggplot2::ggplot(counties_plus, ggplot2::aes(long, lat, group = group)) +
+    ggplot2::geom_polygon(ggplot2::aes(fill = speciesOccurrenceCount)) +
+    ggplot2::coord_map(projection = "azequalarea") +
+    ggplot2::scale_fill_gradient2("", na.value = "lightgrey", low = "white", high = "steelblue") +
+    ggplot2::geom_path(data = counties, colour = "grey", size = .3, alpha = .4) +
+    ggplot2::geom_path(data = states, colour = "grey", size = .4) +
+    ggplot2::theme_bw(base_size = 14) +
+    ggplot2::labs(x = "", y = "") +
+    map_blanktheme() +
+    ggplot2::scale_x_continuous(expand = c(0,0)) +
+    ggplot2::scale_y_continuous(expand = c(0,0))
+}
+
+#' @export
+#' @rdname ns_map
+ns_map_cons <- function(x, ...) {
+  chek_pk("mapproj")
+  chek_pk("ggplot2")
+  chek_pk("maps")
+  nst <- x[[1]]$conservationStatus$natureserve$nationalStatuses
+  nst <- Filter(function(x) NROW(x) > 0, Map(function(a, b) {
+    tmp <- lapply(a$subnationalStatuses, function(x) {
+      utils::modifyList(x, list(rank = status_pick(strsplit(x$rank, ",")[[1]][[1]]) ))
+    })
+    df <- data.table::setDF(
+      data.table::rbindlist(tmp, fill = TRUE, use.names = TRUE)
+    )
+    if (NROW(df) > 0 ) df$country <- b
+    df
+  }, nst, names(nst)))
+  nst <- do.call("rbind", unname(nst))
+  nst$subnationName <- tolower(nst$subnationName)
+  states <- ggplot2::map_data("state")
+  st_plus <- merge(states, nst, by.x = 'region', by.y = 'subnationName', all.x = TRUE)
+  st_plus <- st_plus[order(st_plus$order), ]
+  ggplot2::ggplot(st_plus, ggplot2::aes(long, lat, group = group)) +
+    ggplot2::geom_polygon(ggplot2::aes(fill = rank)) +
+    ggplot2::coord_map(projection = "azequalarea") +
+    ggplot2::geom_path(data = st_plus, colour = "grey", size = .4) +
+    ggplot2::theme_bw(base_size = 14) +
+    ggplot2::labs(x = "", y = "") +
+    map_blanktheme() +
+    ggplot2::scale_x_continuous(expand = c(0,0)) +
+    ggplot2::scale_y_continuous(expand = c(0,0))
+}
+
+#' @export
+#' @rdname ns_map
+ns_map_stpr <- function(x, ...) {
+  chek_pk("mapproj")
+  chek_pk("ggplot2")
+  chek_pk("maps")
+  na <- x[[1]]$distribution$nations
+  na <- Filter(function(x) NROW(x) > 0, Map(function(a, b) {
+    df <- data.table::setDF(
+      data.table::rbindlist(a$subnations, fill = TRUE, use.names = TRUE)
+    )
+    if (NROW(df) > 0 ) df$country <- b
+    df
+  }, na, names(na)))
+  na <- do.call("rbind", unname(na))
+  na$subnationName <- tolower(na$subnationName)
+  na$currentPresenceAbsence <- gsub("Present", "1", na$currentPresenceAbsence)
+  na$currentPresenceAbsence <- gsub("Absent", "0", na$currentPresenceAbsence)
+  na$currentPresenceAbsence <- as.numeric(na$currentPresenceAbsence)
+  states <- ggplot2::map_data("state")
+  st_plus <- merge(states, na, by.x = 'region', by.y = 'subnationName', all.x = TRUE)
+  st_plus <- st_plus[order(st_plus$order),]
+
+  ggplot2::ggplot(st_plus, ggplot2::aes(long, lat, group = group)) +
+    ggplot2::geom_polygon(ggplot2::aes(fill = currentPresenceAbsence)) +
+    ggplot2::coord_map(projection = "azequalarea") +
+    ggplot2::geom_path(data = states, colour = "grey", size = .4) +
+    ggplot2::theme_bw(base_size = 14) +
+    ggplot2::labs(x = "", y = "") +
+    map_blanktheme() +
+    ggplot2::scale_x_continuous(expand = c(0,0)) +
+    ggplot2::scale_y_continuous(expand = c(0,0))
+}
+
+status_pick <- function(w) {
+  stats <- c("SX","SH","S1","S2","S3","S4","S5","SNR","SU","SNA",
+             "SXB", "SHB", "S1B", "S2B", "S3B", "S4B",
+             "S5B", "SNRB", "SUB", "SNAB", "SXN", "SHN",
+             "S1N", "S2N", "S3N", "S4N", "S5N", "SNRN",
+             "SUN", "SNAN", "SXM", "SHM", "S1M", "S2M",
+             "S3M", "S4M", "S5M", "SNRM", "SUM", "SNAM")
+  mm <- Filter(
+    function(x) length(x) > 0,
+    sapply(stats, function(z) str_extrct(w, z)))
+  tmp <- if (length(mm) == 0) {
+    NA_character_
+  } else {
+    mm[[1]]
+  }
+  if (tmp %in% c('SNR', 'SU', 'SNA')) NA else tmp
+}
+
diff --git a/R/ns_search.R b/R/ns_search.R
new file mode 100644
index 0000000..d4de2ba
--- /dev/null
+++ b/R/ns_search.R
@@ -0,0 +1,40 @@
+#' NatureServe taxonomic name search
+#'
+#' @export
+#' @param x (character) A name to search for. An asterisk (*) wildcarded species
+#' name, e.g., 'Aquila chry*'. Name matching is case-insensitive and all of
+#' the primary and synonymous scientific names, along with all common names,
+#' are matched. Required.
+#' @template ns
+#'
+#' @return A tibble (data.frame), with columns:
+#' \itemize{
+#'  \item jurisdictionScientificName - Scientfic name
+#'  \item commonName - Common name
+#'  \item globalSpeciesUid - UID - the taxonomic identifier NatureServe uses
+#'  \item natureServeExplorerURI - URL to get to info online for the taxon
+#'  \item taxonomicComments - comments about the taxon, if any
+#' }
+#'
+#' @examples \dontrun{
+#' ns_search(x = "Ruby*")
+#' ns_search(x = "Helianthus annuus")
+#' ns_search(x = "Ursus americanus")
+#' }
+ns_search <- function(x, key = NULL, ...) {
+  res <- ns_GET(
+    url = paste0(ns_base(), '/v1/globalSpecies/list/nameSearch'),
+    query = list(name = x, NSAccessKeyId = check_key(key)),
+    ...
+  )
+  xml <- xml2::read_xml(res)
+  kids <- xml2::xml_children(xml2::xml_children(xml)[[2]])
+  dat <- lapply(kids, function(z) {
+    data.frame(sapply(xml2::xml_children(z), function(x) {
+      as.list(stats::setNames(xml2::xml_text(x), xml2::xml_name(x)))
+    }), stringsAsFactors = FALSE)
+  })
+  df <- data.table::setDF(data.table::rbindlist(dat, use.names = TRUE, fill = TRUE))
+  df <- move_col2(df, "natureServeExplorerURI")
+  tibble::as_data_frame(df)
+}
diff --git a/R/zzz.R b/R/zzz.R
new file mode 100644
index 0000000..ed42b15
--- /dev/null
+++ b/R/zzz.R
@@ -0,0 +1,71 @@
+mssg <- function(v, ...) if (v) message(...)
+tc <- function(l) Filter(Negate(is.null), l)
+tcnull <- function(x) if (all(sapply(x, is.null))) NULL else x
+
+pluck <- function(x, name, type) {
+  if (missing(type)) {
+    lapply(x, "[[", name)
+  } else {
+    vapply(x, "[[", name, FUN.VALUE = type)
+  }
+}
+
+strtrim <- function(str) {
+  gsub("^\\s+|\\s+$", "", str)
+}
+
+move_col <- function(tt, y){
+  tt[ c(names(tt)[ -sapply(y, function(m) grep(m, names(tt))) ], y) ]
+}
+
+move_col2 <- function(x, y) x[ c(names(x)[-grep(y, names(x))], y) ]
+
+which_name <- function(x, var) {
+  x[which(xml2::xml_name(x) == var)]
+}
+
+parse_if <- function(x, y) {
+  z <- which_name(x, y)
+  if (length(z) == 0) list() else as_list_(z)
+}
+
+parse_if_1 <- function(x, y) {
+  z <- which_name(x, y)
+  if (length(z) == 0) list() else as_list_(z[[1]])
+}
+
+as_list_ <- function(x, y) {
+  unlist(xml2::as_list(x), recursive = FALSE)
+}
+
+ns_base <- function() 'https://services.natureserve.org/idd/rest/ns'
+
+check_key <- function(x) {
+  tmp <- if (is.null(x)) Sys.getenv("NATURE_SERVE_KEY", "") else x
+  if (tmp == "") getOption("NatureServeKey", stop("You need an API key for NatureServe")) else tmp
+}
+
+map_blanktheme <- function(){
+  ggplot2::theme(axis.line = ggplot2::element_blank(),
+        axis.text.x = ggplot2::element_blank(),
+        axis.text.y = ggplot2::element_blank(),
+        axis.ticks = ggplot2::element_blank(),
+        axis.title.x = ggplot2::element_blank(),
+        axis.title.y = ggplot2::element_blank(),
+        panel.background = ggplot2::element_blank(),
+        panel.border = ggplot2::element_blank(),
+        panel.grid.major = ggplot2::element_blank(),
+        panel.grid.minor = ggplot2::element_blank(),
+        plot.background = ggplot2::element_blank(),
+        plot.margin = rep(grid::unit(0,"null"), 4))
+}
+
+chek_pk <- function(x) {
+  if (!requireNamespace(x, quietly = TRUE)) {
+    stop(sprintf("Please install '%s'", x), call. = FALSE)
+  } else {
+    invisible(TRUE)
+  }
+}
+
+str_extrct <- function(string, pattern) regmatches(string, regexpr(pattern, string))
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a47e8b4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,127 @@
+natserv
+=======
+
+
+
+[![Build Status](https://travis-ci.org/ropensci/natserv.svg?branch=master)](https://travis-ci.org/ropensci/natserv)
+[![codecov](https://codecov.io/gh/ropensci/natserv/branch/master/graph/badge.svg)](https://codecov.io/gh/ropensci/natserv)
+[![cran version](http://www.r-pkg.org/badges/version/natserv)](https://cran.r-project.org/package=natserv)
+[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/natserv)](https://github.com/metacran/cranlogs.app)
+
+
+`natserv` NatureServe R client
+
+NatureServe is a non-profit organization that provides wildlife conservation related data to various groups including the public.
+
+* [NatureServe site](https://services.natureserve.org)
+* [NatureServe API docs](https://services.natureserve.org/BrowseServices/getSpeciesData/getSpeciesListREST.jsp)
+
+All functions in this package are prefixed with `ns_` to prevent
+collision with other pkgs.
+
+Three NatureServe web services are available in this package:
+
+* Name lookup (`ns_search`) lookup species Unique IDs (UID) by name. These UIDs are required for access to the more detailed services.
+* Image lookup (`ns_images`) search for metadata for NatureServe images, including the URL's for the image files themselves.
+* Fetch data (`ns_data`) on over 70,000 of the plant and animal species of the United States and Canada.
+
+You'll need an API key to use this package. Get one by signing up at
+<https://services.natureserve.org/developer/index.jsp>
+
+## Installation
+
+Stable version from CRAN
+
+
+```r
+install.packages("natserv")
+```
+
+Development version
+
+
+```r
+install.packages("devtools")
+devtools::install_github("ropensci/natserv")
+```
+
+
+```r
+library('natserv')
+```
+
+## search
+
+
+```r
+ns_search(x = "Helianthus annuus")
+#> # A tibble: 1 × 4
+#>          globalSpeciesUid jurisdictionScientificName       commonName
+#>                     <chr>                      <chr>            <chr>
+#> 1 ELEMENT_GLOBAL.2.134717          Helianthus annuus Common Sunflower
+#> # ... with 1 more variables: natureServeExplorerURI <chr>
+```
+
+## data
+
+
+```r
+res <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+names(res$ELEMENT_GLOBAL.2.100925)
+#>  [1] "uid"                "speciesCode"        "natureserve_uri"   
+#>  [4] "classification"     "economicAttributes" "license"           
+#>  [7] "references"         "conservationStatus" "managementSummary" 
+#> [10] "distribution"
+```
+
+dig into distribution in various watersheds
+
+
+```r
+res$ELEMENT_GLOBAL.2.100925$distribution$watersheds
+#> # A tibble: 458 × 4
+#>     type         watershedName watershedCode speciesOccurrenceCount
+#>    <chr>                 <chr>         <chr>                  <chr>
+#> 1  HUC-8              Allagash      01010002                      1
+#> 2  HUC-8 East Branch Penobscot      01020002                      1
+#> 3  HUC-8        Upper Kennebec      01030001                      1
+#> 4  HUC-8                  Dead      01030002                      7
+#> 5  HUC-8        Lower Kennebec      01030003                      1
+#> 6  HUC-8    Upper Androscoggin      01040001                      2
+#> 7  HUC-8    Lower Androscoggin      01040002                      2
+#> 8  HUC-8                  Saco      01060002                      4
+#> 9  HUC-8          Upper Hudson      02020001                      3
+#> 10 HUC-8      Hudson-Wappinger      02020008                      2
+#> # ... with 448 more rows
+```
+
+## image metadata
+
+
+```r
+res <- ns_images(commonName = "*eagle", resolution = 'thumbnail')
+res$images[[1]][1:5]
+#> $id
+#> [1] "16968"
+#> 
+#> $scientificName
+#> [1] "Haliaeetus leucocephalus"
+#> 
+#> $commonName
+#> [1] "Bald Eagle"
+#> 
+#> $otherCommonName
+#> [1] "pygargue à tête blanche"
+#> 
+#> $otherCommonName
+#> [1] "Águila Cabeza Blanca"
+```
+
+## Meta
+
+* Please [report any issues or bugs](https://github.com/ropensci/natserv/issues).
+* License: MIT
+* Get citation information for `natserv` in R doing `citation(package = 'natserv')`
+* Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
+
+[![ropensci](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)
diff --git a/data/sysdata.rda b/data/sysdata.rda
new file mode 100644
index 0000000..7ff4126
Binary files /dev/null and b/data/sysdata.rda differ
diff --git a/debian/README.test b/debian/README.test
deleted file mode 100644
index 90657cf..0000000
--- a/debian/README.test
+++ /dev/null
@@ -1,8 +0,0 @@
-Notes on how this package can be tested.
-────────────────────────────────────────
-
-This package can be tested by running the provided test:
-
-    sh run-unit-test
-
-in order to confirm its integrity.
diff --git a/debian/changelog b/debian/changelog
deleted file mode 100644
index 449a6ec..0000000
--- a/debian/changelog
+++ /dev/null
@@ -1,5 +0,0 @@
-r-cran-natserv (0.1.4-1) unstable; urgency=medium
-
-  * Initial release (closes: #851957)
-
- -- Andreas Tille <tille at debian.org>  Fri, 20 Jan 2017 12:40:53 +0100
diff --git a/debian/compat b/debian/compat
deleted file mode 100644
index f599e28..0000000
--- a/debian/compat
+++ /dev/null
@@ -1 +0,0 @@
-10
diff --git a/debian/control b/debian/control
deleted file mode 100644
index 62dd371..0000000
--- a/debian/control
+++ /dev/null
@@ -1,28 +0,0 @@
-Source: r-cran-natserv
-Maintainer: Debian Med Packaging Team <debian-med-packaging at lists.alioth.debian.org>
-Uploaders: Andreas Tille <tille at debian.org>
-Section: gnu-r
-Priority: optional
-Build-Depends: debhelper (>= 10),
-               dh-r,
-               r-base-dev,
-               r-cran-xml2 (>= 1.0.0),
-               r-cran-tibble,
-               r-cran-data.table (>= 1.10.0),
-               r-cran-crul
-Standards-Version: 3.9.8
-Vcs-Browser: https://anonscm.debian.org/viewvc/debian-med/trunk/packages/R/r-cran-natserv/trunk/
-Vcs-Svn: svn://anonscm.debian.org/debian-med/trunk/packages/R/r-cran-natserv/trunk/
-Homepage: https://cran.r-project.org/package=natserv
-
-Package: r-cran-natserv
-Architecture: all
-Depends: ${R:Depends},
-         ${shlibs:Depends},
-         ${misc:Depends}
-Recommends: ${R:Recommends}
-Suggests: ${R:Suggests}
-Description: GNU R 'NatureServe' Interface
- Interface to 'NatureServe' (<http://www.natureserve.org>).
- Includes methods to get data, image metadata, search taxonomic names,
- and make maps.
diff --git a/debian/copyright b/debian/copyright
deleted file mode 100644
index 2bbee91..0000000
--- a/debian/copyright
+++ /dev/null
@@ -1,32 +0,0 @@
-Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
-Upstream-Name: natserv
-Upstream-Contact: Scott Chamberlain <myrmecocystus at gmail.com>
-Source: https://cran.r-project.org/package=natserv
-
-Files: *
-Copyright: 2015-2017 Scott Chamberlain
-License: MIT
-
-Files: debian/*
-Copyright: 2017 Andreas Tille <tille at debian.org>
-License: MIT
-
-License: MIT
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
- .
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- .
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/debian/docs b/debian/docs
deleted file mode 100644
index 6466d39..0000000
--- a/debian/docs
+++ /dev/null
@@ -1,3 +0,0 @@
-debian/tests/run-unit-test
-debian/README.test
-tests
diff --git a/debian/rules b/debian/rules
deleted file mode 100755
index 529c38a..0000000
--- a/debian/rules
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/make -f
-
-%:
-	dh $@ --buildsystem R
-
diff --git a/debian/source/format b/debian/source/format
deleted file mode 100644
index 163aaf8..0000000
--- a/debian/source/format
+++ /dev/null
@@ -1 +0,0 @@
-3.0 (quilt)
diff --git a/debian/tests/control b/debian/tests/control
deleted file mode 100644
index a62fb6e..0000000
--- a/debian/tests/control
+++ /dev/null
@@ -1,5 +0,0 @@
-Tests: run-unit-test
-Depends: @, r-cran-testthat,
-Restrictions: allow-stderr
-
-
diff --git a/debian/tests/run-unit-test b/debian/tests/run-unit-test
deleted file mode 100644
index 4ce1646..0000000
--- a/debian/tests/run-unit-test
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh -e
-
-pkgname=natserv
-debname=r-cran-natserv
-
-if [ "$ADTTMP" = "" ] ; then
-    ADTTMP=`mktemp -d /tmp/${debname}-test.XXXXXX`
-    trap "rm -rf $ADTTMP" 0 INT QUIT ABRT PIPE TERM
-fi
-cd $ADTTMP
-cp -a /usr/share/doc/$debname/tests/* $ADTTMP
-gunzip -r *
-for testfile in *.R; do
-    echo "BEGIN TEST $testfile"
-    LC_ALL=C R --no-save < $testfile
-done
-
diff --git a/debian/watch b/debian/watch
deleted file mode 100644
index 944a534..0000000
--- a/debian/watch
+++ /dev/null
@@ -1,2 +0,0 @@
-version=4
-https://cran.r-project.org/src/contrib/natserv_([-\d.]*)\.tar\.gz
diff --git a/man/nat_states.Rd b/man/nat_states.Rd
new file mode 100644
index 0000000..73f387d
--- /dev/null
+++ b/man/nat_states.Rd
@@ -0,0 +1,14 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/natserv-package.R
+\docType{data}
+\name{nat_states}
+\alias{nat_states}
+\title{A data.frame with 49 rows and 2 columns}
+\description{
+\itemize{
+  \item state (character) state 2 letter abbreviation
+  \item state_name (character) state full name
+}
+}
+\keyword{data}
+
diff --git a/man/natserv-package.Rd b/man/natserv-package.Rd
new file mode 100644
index 0000000..1652838
--- /dev/null
+++ b/man/natserv-package.Rd
@@ -0,0 +1,15 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/natserv-package.R
+\docType{package}
+\name{natserv-package}
+\alias{natserv}
+\alias{natserv-package}
+\title{natserv}
+\description{
+natserv
+}
+\author{
+Scott Chamberlain \email{myrmecocystus at gmail.com}
+}
+\keyword{package}
+
diff --git a/man/ns_data.Rd b/man/ns_data.Rd
new file mode 100644
index 0000000..78526c5
--- /dev/null
+++ b/man/ns_data.Rd
@@ -0,0 +1,120 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ns_data.R
+\name{ns_data}
+\alias{ns_data}
+\title{NatureServe data}
+\usage{
+ns_data(uid, key = NULL, ...)
+}
+\arguments{
+\item{uid}{(character) a species UID, e.g., ELEMENT_GLOBAL.2.100925}
+
+\item{key}{(character) API key. Required. See \strong{Authentication} below
+for more.}
+
+\item{...}{Curl options passed on to \code{\link[httr]{GET}}}
+}
+\value{
+a named list, with possible slots:
+\itemize{
+ \item natureserve_uri
+ \item classification
+ \item economicAttributes
+ \item license
+ \item references
+ \item conservationStatus
+ \item managementSummary
+ \item distribution
+}
+}
+\description{
+NatureServe data
+}
+\section{Authentication}{
+
+Get an API key from NatureServe at
+\url{https://services.natureserve.org/developer/index.jsp}.
+You can pass your token in as an argument or store it one of two places:
+
+\itemize{
+  \item your .Rprofile file with an entry like
+  \code{options(NatureServeKey = "your-natureserve-key")}
+  \item your .Renviron file with an entry like
+  \code{NATURE_SERVE_KEY=your-natureserve-key}
+}
+
+See \code{\link{Startup}} for information on how to create/find your
+.Rrofile and .Renviron files
+}
+
+\section{National (N) and Subnational (S) Conservation Status Ranks}{
+
+\itemize{
+ \item NX,SX - Presumed Extirpated - Species or community is believed to be
+ extirpated from the nation or state/province. Not located despite intensive
+ searches of historical sites and other appropriate habitat, and virtually
+ no likelihood that it will be rediscovered.
+ \item NH,SH - Possibly Extirpated (Historical) - Species or community
+ occurred historically in the nation or state/province, and there is some
+ possibility that it may be rediscovered. Its presence may not have been
+ verified in the past 20-40 years. A species or community could become NH
+ or SH without such a 20-40 year delay if the only known occurrences in a
+ nation or state/province were destroyed or if it had been extensively and
+ unsuccessfully looked for. The NH or SH rank is reserved for species or
+ communities for which some effort has been made to relocate occurrences,
+ rather than simply using this status for all elements not known from
+ verified extant occurrences.
+ \item N1,S1 - Critically Imperiled - Critically imperiled in the nation or
+ state/province because of extreme rarity (often 5 or fewer occurrences)
+ or because of some factor(s) such as very steep declines making it
+ especially vulnerable to extirpation from the state/province.
+ \item N2,S2 - Imperiled - Imperiled in the nation or state/province because
+ of rarity due to very restricted range, very few populations (often 20 or
+ fewer), steep declines, or other factors making it very vulnerable to
+ extirpation from the nation or state/province.
+ \item N3,S3 - Vulnerable - Vulnerable in the nation or state/province due
+ to a restricted range, relatively few populations (often 80 or fewer),
+ recent and widespread declines, or other factors making it vulnerable
+ to extirpation.
+ \item N4,S4 - Apparently Secure - Uncommon but not rare; some cause for
+ long-term concern due to declines or other factors.
+ \item N5,S5 - Secure - Common, widespread, and abundant in the nation or
+ state/province.
+ \item NNR,SNR - Unranked - Nation or state/province conservation status
+ not yet assessed.
+ \item NU,SU - Unrankable - Currently unrankable due to lack of information
+ or due to substantially conflicting information about status or trends.
+ \item NNA,SNA - Not Applicable - A conservation status rank is not
+ applicable because the species is not a suitable target for conservation
+ activities.
+}
+}
+
+\section{Breeding Status Qualifiers}{
+
+\itemize{
+ \item B - Breeding - Conservation status refers to the breeding population of
+ the species in the nation or state/province.
+ \item N - Nonbreeding - Conservation status refers to the non-breeding
+ population of the species in the nation or state/province.
+ \item M - Migrant - Migrant species occurring regularly on migration at
+ particular staging areas or concentration spots where the species might
+ warrant conservation attention. Conservation status refers to the
+ aggregating transient population of the species in the nation or
+ state/province.
+}
+}
+\examples{
+\dontrun{
+## single id
+(res <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925'))
+## many ids at once
+res <- ns_data(uid = c('ELEMENT_GLOBAL.2.100925', 'ELEMENT_GLOBAL.2.104470'))
+res$ELEMENT_GLOBAL.2.100925
+res$ELEMENT_GLOBAL.2.104470
+}
+}
+\references{
+\url{https://services.natureserve.org/index.jsp}
+}
+
diff --git a/man/ns_images.Rd b/man/ns_images.Rd
new file mode 100644
index 0000000..dd07ce3
--- /dev/null
+++ b/man/ns_images.Rd
@@ -0,0 +1,101 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ns_images.R
+\name{ns_images}
+\alias{ns_images}
+\title{NatureServe image metadata}
+\usage{
+ns_images(uid = NULL, scientificName = NULL, commonName = NULL,
+  includeSynonyms = NULL, resolution = NULL, ITISNames = NULL,
+  key = NULL, ...)
+}
+\arguments{
+\item{uid}{(character) a species UID, e.g., ELEMENT_GLOBAL.2.100925}
+
+\item{scientificName}{(character) An asterisk (*) wildcarded species
+scientific name, e.g., 'Aquila chry*'. Name matching is case-insensitive.}
+
+\item{commonName}{(character) An asterisk (*) wildcarded species common
+name, e.g., 'g*EAGLE'. Name matching is case-insensitive.}
+
+\item{includeSynonyms}{(character)    An optional parameter, relevant to
+scientific or common name queries, that indicates whether to include
+synonymous names in the query, as follows:
+\itemize{
+ \item Y (or y) - search the Primary and all synonymous Scientific and
+ Common Names
+ \item Any other value, or omitted - search only the Primary Scientific
+ and Common Name fields
+}}
+
+\item{resolution}{(character)    An optional parameter that restricts output
+to images at a certain resolution. The value can be of one of the following.
+\itemize{
+ \item lowest - return only the lowest resolution version of images
+ \item highest - return only the highest resolution version of images
+ \item thumbnail - return only the version NatureServe deems the
+ 'thumbnail image'
+ \item web - return only the version NatureServe deems the 'web image'
+}
+The omission of this parameter leads to the return of metadata for images at
+all available resolutions.}
+
+\item{ITISNames}{(character)    An optional parameter, relevant to scientific
+or common name queries, that will indicate whether to restrict queries to
+ITIS names, as follows.
+\itemize{
+ \item Y (or y) - query using ITIS names
+ \item Any other value, or omitted - query using NatureServe names
+}
+NOTE: This parameter is a placeholder only and will not affect processing.
+At present, searching by ITIS names is not possible.}
+
+\item{key}{(character) API key. Required. See \strong{Authentication} below
+for more.}
+
+\item{...}{Curl options passed on to \code{\link[httr]{GET}}}
+}
+\value{
+a list with terms and images
+}
+\description{
+NatureServe image metadata
+}
+\details{
+Note that the NatureServer servers apparently want Windows
+HTML encoding (Windows-1252), instead of UTF-8, so some accents
+and such may not work
+}
+\section{Authentication}{
+
+Get an API key from NatureServe at
+\url{https://services.natureserve.org/developer/index.jsp}.
+You can pass your token in as an argument or store it one of two places:
+
+\itemize{
+  \item your .Rprofile file with an entry like
+  \code{options(NatureServeKey = "your-natureserve-key")}
+  \item your .Renviron file with an entry like
+  \code{NATURE_SERVE_KEY=your-natureserve-key}
+}
+
+See \code{\link{Startup}} for information on how to create/find your
+.Rrofile and .Renviron files
+}
+\examples{
+\dontrun{
+# search by uid
+ns_images(uid = 'ELEMENT_GLOBAL.2.100925')
+
+# search by common name and resolutio thumbnail
+(res <- ns_images(commonName = "*eagle", resolution = 'thumbnail'))
+
+# search "Ruby*", all common names [in any language], and highest
+# resolution only:
+(res <- ns_images(commonName = "Ruby*", includeSynonyms = 'y',
+  resolution = 'highest'))
+}
+}
+\references{
+\url{https://services.natureserve.org/index.jsp}
+}
+
diff --git a/man/ns_map.Rd b/man/ns_map.Rd
new file mode 100644
index 0000000..410a303
--- /dev/null
+++ b/man/ns_map.Rd
@@ -0,0 +1,39 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ns_map.R
+\name{ns_map}
+\alias{ns_map}
+\alias{ns_map_cons}
+\alias{ns_map_county}
+\alias{ns_map_stpr}
+\title{Map NatureServe data}
+\usage{
+ns_map_county(x, ...)
+
+ns_map_cons(x, ...)
+
+ns_map_stpr(x, ...)
+}
+\arguments{
+\item{x}{the result of a call to \code{\link{ns_data}}}
+
+\item{...}{ignored}
+}
+\description{
+Map NatureServe data
+}
+\examples{
+\dontrun{
+# Aquila chrysaetos
+x <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+ns_map_county(x)
+ns_map_cons(x)
+ns_map_stpr(x)
+
+# Ursus americanus
+x <- ns_data('ELEMENT_GLOBAL.2.100661')
+ns_map_county(x)
+ns_map_cons(x)
+ns_map_stpr(x)
+}
+}
+
diff --git a/man/ns_search.Rd b/man/ns_search.Rd
new file mode 100644
index 0000000..da995e3
--- /dev/null
+++ b/man/ns_search.Rd
@@ -0,0 +1,59 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ns_search.R
+\name{ns_search}
+\alias{ns_search}
+\title{NatureServe taxonomic name search}
+\usage{
+ns_search(x, key = NULL, ...)
+}
+\arguments{
+\item{x}{(character) A name to search for. An asterisk (*) wildcarded species
+name, e.g., 'Aquila chry*'. Name matching is case-insensitive and all of
+the primary and synonymous scientific names, along with all common names,
+are matched. Required.}
+
+\item{key}{(character) API key. Required. See \strong{Authentication} below
+for more.}
+
+\item{...}{Curl options passed on to \code{\link[httr]{GET}}}
+}
+\value{
+A tibble (data.frame), with columns:
+\itemize{
+ \item jurisdictionScientificName - Scientfic name
+ \item commonName - Common name
+ \item globalSpeciesUid - UID - the taxonomic identifier NatureServe uses
+ \item natureServeExplorerURI - URL to get to info online for the taxon
+ \item taxonomicComments - comments about the taxon, if any
+}
+}
+\description{
+NatureServe taxonomic name search
+}
+\section{Authentication}{
+
+Get an API key from NatureServe at
+\url{https://services.natureserve.org/developer/index.jsp}.
+You can pass your token in as an argument or store it one of two places:
+
+\itemize{
+  \item your .Rprofile file with an entry like
+  \code{options(NatureServeKey = "your-natureserve-key")}
+  \item your .Renviron file with an entry like
+  \code{NATURE_SERVE_KEY=your-natureserve-key}
+}
+
+See \code{\link{Startup}} for information on how to create/find your
+.Rrofile and .Renviron files
+}
+\examples{
+\dontrun{
+ns_search(x = "Ruby*")
+ns_search(x = "Helianthus annuus")
+ns_search(x = "Ursus americanus")
+}
+}
+\references{
+\url{https://services.natureserve.org/index.jsp}
+}
+
diff --git a/tests/test-all.R b/tests/test-all.R
new file mode 100644
index 0000000..738d497
--- /dev/null
+++ b/tests/test-all.R
@@ -0,0 +1,2 @@
+library("testthat")
+test_check("natserv")
diff --git a/tests/testthat/helper_data.R b/tests/testthat/helper_data.R
new file mode 100644
index 0000000..02137f5
--- /dev/null
+++ b/tests/testthat/helper_data.R
@@ -0,0 +1 @@
+load("ns_data_output.rda")
diff --git a/tests/testthat/ns_data_output.rda b/tests/testthat/ns_data_output.rda
new file mode 100644
index 0000000..1f567f3
Binary files /dev/null and b/tests/testthat/ns_data_output.rda differ
diff --git a/tests/testthat/test-ns_data.R b/tests/testthat/test-ns_data.R
new file mode 100644
index 0000000..ef16b5c
--- /dev/null
+++ b/tests/testthat/test-ns_data.R
@@ -0,0 +1,14 @@
+context("ns_data")
+
+test_that("ns_data works as expected", {
+  skip_on_cran()
+
+  aa <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+
+  expect_is(aa, 'list')
+  expect_is(aa[[1]], 'list')
+  expect_is(aa[[1]]$distribution, 'list')
+  expect_is(aa[[1]]$distribution$countyDistribution$US$AZ, 'data.frame')
+
+  expect_match(aa[[1]]$natureserve_uri, 'explorer.natureserve.org')
+})
diff --git a/tests/testthat/test-ns_images.R b/tests/testthat/test-ns_images.R
new file mode 100644
index 0000000..1bf37f5
--- /dev/null
+++ b/tests/testthat/test-ns_images.R
@@ -0,0 +1,14 @@
+context("ns_images")
+
+test_that("ns_images works as expected", {
+  skip_on_cran()
+
+  aa <- ns_images(uid = 'ELEMENT_GLOBAL.2.100925')
+
+  expect_is(aa, 'list')
+  expect_named(aa, c('terms', 'images'))
+  expect_is(aa$terms, 'character')
+  expect_is(aa$images, 'list')
+  expect_is(aa$images[[1]], 'list')
+  expect_is(aa$images[[1]]$id, 'character')
+})
diff --git a/tests/testthat/test-ns_map.R b/tests/testthat/test-ns_map.R
new file mode 100644
index 0000000..104597d
--- /dev/null
+++ b/tests/testthat/test-ns_map.R
@@ -0,0 +1,47 @@
+context("ns_map")
+
+test_that("ns_map_county works as expected", {
+  skip_on_cran()
+
+  #dat <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+  aa <- ns_map_county(ns_data_output)
+
+  expect_is(aa, 'gg')
+  expect_is(aa, 'ggplot')
+  expect_is(aa$data, 'data.frame')
+  expect_is(aa$layers, 'list')
+})
+
+test_that("ns_map_county works as expected", {
+  skip_on_cran()
+
+  #dat <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+  aa <- ns_map_cons(ns_data_output)
+
+  expect_is(aa, 'gg')
+  expect_is(aa, 'ggplot')
+  expect_is(aa$data, 'data.frame')
+  expect_is(aa$layers, 'list')
+})
+
+test_that("ns_map_county works as expected", {
+  skip_on_cran()
+
+  #dat <- ns_data(uid = 'ELEMENT_GLOBAL.2.100925')
+  aa <- ns_map_stpr(ns_data_output)
+
+  expect_is(aa, 'gg')
+  expect_is(aa, 'ggplot')
+  expect_is(aa$data, 'data.frame')
+  expect_is(aa$layers, 'list')
+})
+
+test_that("ns_map fails well", {
+  skip_on_cran()
+
+  expect_error(ns_map_county(),
+               'argument "x" is missing')
+
+  expect_error(ns_map_county(5),
+               'inherits\\(x, "list"\\) is not TRUE')
+})
diff --git a/tests/testthat/test-ns_search.R b/tests/testthat/test-ns_search.R
new file mode 100644
index 0000000..47e77df
--- /dev/null
+++ b/tests/testthat/test-ns_search.R
@@ -0,0 +1,15 @@
+context("ns_search")
+
+test_that("ns_search works as expected", {
+  skip_on_cran()
+
+  aa <- ns_search(x = "Helianthus annuus")
+
+  expect_is(aa, 'tbl_df')
+  expect_is(aa$globalSpeciesUid, 'character')
+  expect_is(aa$jurisdictionScientificName, 'character')
+  expect_is(aa$commonName, 'character')
+  expect_is(aa$natureServeExplorerURI, 'character')
+
+  expect_equal(aa$jurisdictionScientificName, 'Helianthus annuus')
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-natserv.git



More information about the debian-med-commit mailing list