natserv/0000755000176200001440000000000013033026177011736 5ustar liggesusersnatserv/tests/0000755000176200001440000000000013033003731013067 5ustar liggesusersnatserv/tests/testthat/0000755000176200001440000000000013033003731014727 5ustar liggesusersnatserv/tests/testthat/test-ns_map.R0000644000176200001440000000203213024373356017316 0ustar liggesuserscontext("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') }) natserv/tests/testthat/test-ns_images.R0000644000176200001440000000053512764644143020021 0ustar liggesuserscontext("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') }) natserv/tests/testthat/test-ns_search.R0000644000176200001440000000064212764643620020017 0ustar liggesuserscontext("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') }) natserv/tests/testthat/ns_data_output.rda0000644000176200001440000005123413024373000020454 0ustar liggesusersIl$Y \{-32 ݃GUVdVtFww%<` Z 1Aj4L $@t$itMne 堖.7{;ʠvuok*-j֭[oݹs;m[wo݃W}6a_EdN'5?${jkX*++R*Z}.Vp2?}{=؋!xWx'&C/?&d HBf}o,A7~u^GʙY.gތ2 k7N8gi<J+N2*xH]Kz?挚Yli?) U9η*}O1a{<ȬP(> On&3>:c{HX,2v )HmP>KszKgp:Jm]Ђ'FCC[3bch+2PPdN1A*' DIfONYr>-':88JW w@NW2}Swz㇀# l=rwaDx֫Eg5]@Su}9逳(ae8mR+TݲdH 0:Eg?PN0DKf13|^XN6G/ήw|'ENu]\K^7dy3vK\9NZӟQrF Yp 6vb`#o`=d0ekO Ny}Բ@b} @-:}ɽȻ01vS?A(a88rL <[AJBBz HgQ Xi9{;#G]j _PA$,jD>H8JEp3EK#$A 'DJAx6@S1g9prE(qkO]wບ'ƼH|:=3/PY ~ D9$V4tOČއLps㧥B4;ˈ.ϸT A+èA/Ŷ>ʢ 2c]QPړǘ-J%bj( sxb g!l^s]JA8Fs R{ VtG 0G΁Sx C@{0 茅\<h\fAJ3jM+ k.A"Տ^L:@yYFM},4F0X-8ץ H=i}(3 A^"hʵ̼AȱaFNRR'`P$g#q @LHP8"#Y _WJJ;{ ;% gAD1٩{C٘Y?j?VܠǪD)?9yyLX-gӦ VpMHXD$8ʞ ơs?ׂ=2О7p=^z[}pSqYYCrѠyI%>z-`g- ^ꡒה@aln{Ja&MW8N}-IG0Aa#:,um˦T{ pL >)7VjM?_A[J:d#9zJʒ{LO%@VZ 7i08_N*PH[C\m+:s؃~=PL=#}gGI /q6 mCy u%_%V/P'Ӛf T (ecqh!ゃ~A0PrPWaN̵r&~{@M|nt*+b7@qEֽK% :P< ƾ:ml Z( PG6~uz0*.#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mhNSY3peJ&ѼD%WRI?Z(P kbl4Q'ghoD0;M8&x7z@4.đ~qq׏qv4neqXw^݀Zyd~z/2yIvK!xJzaLUD$\ڀKpi.m h%@6P he@6P ie@6P T.8ke/*fzdʌά n6]~LvUI=wZmɮwJٽNZ[ߩxtVZN說rRSd 6 #ݩAPA &5T W~m_/:׶;׮_/կׁѭ_/uG/M;h/;S*^"ďxiJ ˂ȗ"^&z[l->*cAk~2n-VoIBgiq*Ն?pXT |^k"zbϡ)5B#0H_>o <^3ώR?_<@5;?X^Y=jc{o],IE~_+Wgnatserv/tests/testthat/helper_data.R0000644000176200001440000000003313024373332017325 0ustar liggesusersload("ns_data_output.rda") natserv/tests/testthat/test-ns_data.R0000644000176200001440000000056112764644045017465 0ustar liggesuserscontext("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') }) natserv/tests/test-all.R0000644000176200001440000000005212764647465014770 0ustar liggesuserslibrary("testthat") test_check("natserv") natserv/NAMESPACE0000644000176200001440000000024013023711074013145 0ustar liggesusers# 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) natserv/NEWS.md0000644000176200001440000000034413033003202013015 0ustar liggesusersnatserv 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 natserv/data/0000755000176200001440000000000013023712657012653 5ustar liggesusersnatserv/data/sysdata.rda0000644000176200001440000000133312766647212015022 0ustar liggesusersTYn0Ul^I4S$icXSARVܯް7KٚQ( y3~A+hwVð?;Am7ApוGBWN ]At w֞ٳ!;&fc_\Ϟ"bRn } PLT(i焨H)&kb!7>](;q.H@dM+4{`,X RLQ<@+{i8s].+U"3HO#<&Dםz69hgRR j  ϒ͹r9*/u.쓥 B JJ*{rGfb 3`CLX[>Xsv7zO 9.{Q ¦:(rcH5mWƥ}1~M`^TK5/3\)KdhRH'!vYe=-T;?~,$ ] >AbjH^nBXVWXiƅa7CuX 7dZYmoaM d78R~+wY?`syW+l=Hh~o`Z74k3f)`LSxas}| 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 } natserv/R/globals.R0000644000176200001440000000031513024076313013701 0ustar liggesusersif (base::getRversion() >= "2.15.1") { utils::globalVariables( c("currentPresenceAbsence", "element_blank", "group", "lat", "long", "speciesOccurrenceCount", "theme", "unit", "nat_states") ) } natserv/R/http.R0000644000176200001440000000026313032637132013240 0ustar liggesusersns_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") } natserv/R/zzz.R0000644000176200001440000000400613023711727013120 0ustar liggesusersmssg <- 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)) natserv/README.md0000644000176200001440000001012113033001676013205 0ustar liggesusersnatserv ======= [![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 ## 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 #> #> 1 ELEMENT_GLOBAL.2.134717 Helianthus annuus Common Sunflower #> # ... with 1 more variables: natureServeExplorerURI ``` ## 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 #> #> 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) natserv/MD50000644000176200001440000000255613033026177012256 0ustar liggesusersf5f61a30ce3ca67d45756bec1ab073f5 *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 natserv/DESCRIPTION0000644000176200001440000000161713033026177013451 0ustar liggesusersPackage: natserv Title: 'NatureServe' Interface Description: Interface to 'NatureServe' (). 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@R: c( person("Scott", "Chamberlain", role = c("aut", "cre"), email = "myrmecocystus@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 Repository: CRAN Date/Publication: 2017-01-03 23:58:07 natserv/man/0000755000176200001440000000000013033003731012500 5ustar liggesusersnatserv/man/ns_data.Rd0000644000176200001440000001070713023711074014412 0ustar liggesusers% 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} } natserv/man/natserv-package.Rd0000644000176200001440000000045112764644741016070 0ustar liggesusers% 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@gmail.com} } \keyword{package} natserv/man/ns_map.Rd0000644000176200001440000000121713024075657014265 0ustar liggesusers% 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) } } natserv/man/ns_search.Rd0000644000176200001440000000325512765301633014756 0ustar liggesusers% 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} } natserv/man/nat_states.Rd0000644000176200001440000000052513024075403015143 0ustar liggesusers% 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} natserv/man/ns_images.Rd0000644000176200001440000000647313023711074014753 0ustar liggesusers% 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} } natserv/LICENSE0000644000176200001440000000005713033003026012731 0ustar liggesusersYEAR: 2017 COPYRIGHT HOLDER: Scott Chamberlain