ropensci / natserv

:warning: ARCHIVED :warning: NatureServe R client
Other
11 stars 7 forks source link

In `ns_search_spp` need to provide `kingdom` as well as `level`? #25

Closed mikeroswell closed 2 years ago

mikeroswell commented 2 years ago

I can download all plants: ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Plantae", level = "kingdom")) works, but if I try to download a group of animals, I get a 505 error: ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order")) # 505 error

I wonder if this is because when level !="kingdom" kingdom must also be supplied, based on the documentation here. This is just a guess!

Thanks for your help!!!

Session Info ```r ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Plantae", level = "kingdom")) # works ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order")) # 505 error R version 4.1.2 (2021-11-01) -- "Bird Hippie" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin17.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > #get bug occurrences and statuses > # update natserv from time to tim > # remotes::install_github("ropensci/natserv") > library(natserv) #this is how we get naturserve status > library(rgbif) #how we get gbif observations > library(tidyverse) ── Attaching packages ───────────────────────────────────────────────── tidyverse 1.3.1 ── ✓ ggplot2 3.3.5 ✓ purrr 0.3.4 ✓ tibble 3.1.6 ✓ dplyr 1.0.7 ✓ tidyr 1.1.4 ✓ stringr 1.4.0 ✓ readr 2.1.1 ✓ forcats 0.5.1 ── Conflicts ──────────────────────────────────────────────────── tidyverse_conflicts() ── x dplyr::filter() masks stats::filter() x dplyr::lag() masks stats::lag() > library(patchwork) > # when downloading data from gbif, will need to combine different record types into DF > bind.gbif<-function(gbif){bind_rows(gbif[[2]][[3]], gbif[[3]][[3]])} > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order") + , location = list(nation ="US", subnation ="MD") #this filters to only include species that have a MD status, but retains status for all localities + , page = 0 + , per_page = 5e3)[[1]] %>% + unnest(cols=nations) %>% + unnest (cols = "subnations", names_repair ="unique") %>% + filter(subnationCode == "MD") #here is the step where I drop other localities, but this could be dropped at some point. Error: Internal Server Error (HTTP 500) > traceback() 8: stop(sprintf("%s (HTTP %s)", x$message, x$status_code), call. = FALSE) 7: temp$raise_for_status() 6: ns_POST(url = file.path(ns_base(), "api/data/speciesSearch"), body = list(criteriaType = "species", textCriteria = list(text) %|lst|% NULL, statusCriteria = list(status) %|lst|% NULL, locationCriteria = list(location) %|lst|% NULL, speciesTaxonomyCriteria = list(species_taxonomy) %|lst|% NULL, recordSubtypeCriteria = list(record_subtype) %|lst|% NULL, pagingOptions = paging, modifiedSince = modified_since), ...) 5: ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order"), location = list(nation = "US", subnation = "MD"), page = 0, per_page = 5000) 4: unnest(., cols = nations) 3: unnest(., cols = "subnations", names_repair = "unique") 2: filter(., subnationCode == "MD") 1: ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order"), location = list(nation = "US", subnation = "MD"), page = 0, per_page = 5000)[[1]] %>% unnest(cols = nations) %>% unnest(cols = "subnations", names_repair = "unique") %>% filter(subnationCode == "MD") > #next, download status classifications from natureserve > plant_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Plantae", level = "kingdom") + , location = list(nation ="US", subnation ="MD") #this filters to only include species that have a MD status, but retains status for all localities + , page = 0 + , per_page = 5e3)[[1]] %>% + unnest(cols=nations) %>% + unnest (cols = "subnations", names_repair ="unique") %>% + filter(subnationCode == "MD") #here is the step where I drop other localities, but this could be dropped at some point. New names: * exotic -> exotic...15 * native -> native...16 * exotic -> exotic...17 * native -> native...18 > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "Order") + , location = list(nation ="US", subnation ="MD") #this filters to only include species that have a MD status, but retains status for all localities + , page = 0 + , per_page = 5e3)[[1]] %>% + unnest(cols=nations) %>% + unnest (cols = "subnations", names_repair ="unique") %>% + filter(subnationCode == "MD") #here is the step where I drop other localities, but this could be dropped at some point. Error: Internal Server Error (HTTP 500) > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order") + , location = list(nation ="US", subnation ="MD") #this filters to only include species that have a MD status, but retains status for all localities + , page = 0 + , per_page = 5e3)[[1]] %>% + unnest(cols=nations) %>% + unnest (cols = "subnations", names_repair ="unique") %>% + filter(subnationCode == "MD") #here is the step where I drop other localities, but this could be dropped at some point. Error: Internal Server Error (HTTP 500) > ?ns_search_spp > ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order")) Error: Internal Server Error (HTTP 500) > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Hymenoptera", level = "order") + , location = list(nation ="US", subnation ="MD") #this filters to only include species that have a MD status, but retains status for all localities + , page = 0 + , per_page = 5e3)[[1]] %>% + unnest(cols=nations) %>% + unnest (cols = "subnations", names_repair ="unique") %>% + filter(subnationCode == "MD") #here is the step where I drop other localities, but this could be dropped at some point. Error: Internal Server Error (HTTP 500) > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Insecta", level = "class") + , location = list(nation ="US", subnation ="MD") #this filters to only include species that have a MD status, but retains status for all localities + , page = 0 + , per_page = 5e3)[[1]] %>% + unnest(cols=nations) %>% + unnest (cols = "subnations", names_repair ="unique") %>% + filter(subnationCode == "MD") #here is the step where I drop other localities, but this could be dropped at some point. Error: Internal Server Error (HTTP 500) > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Insecta", level = "class")) Error: Internal Server Error (HTTP 500) > ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Bombus", level = "genus")) Error: Internal Server Error (HTTP 500) > ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Plantae", level = "kingdom")) $results # A tibble: 20 × 15 recordType elementGlobalId uniqueId nsxUrl elcode scientificName formattedScientif… primaryCommonNa… primaryCommonNa… 1 SPECIES 137101 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes acadie… Isoetes acadie… Acadian Quillwo… EN 2 SPECIES 159182 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes appala… Isoetes appala… Appalachian Qui… EN 3 SPECIES 141815 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes boland… Isoetes boland… Bolander's Quil… EN 4 SPECIES 138575 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes boomii Isoetes boomii… Boom's Quillwort EN 5 SPECIES 135589 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes butleri Isoetes butler… Butler's Quillw… EN 6 SPECIES 136878 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes echino… Isoetes echino… Spiny-spore Qui… EN 7 SPECIES 151042 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes engelm… Isoetes engelm… Engelmann's Qui… EN 8 SPECIES 150693 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes flacci… Isoetes flacci… Southern Quillw… EN 9 SPECIES 152181 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes flacci… Isoetes flacci… Southern Quillw… EN 10 SPECIES 128727 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes flacci… Isoetes flacci… Southern Quillw… EN 11 SPECIES 145484 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes flacci… Isoetes flacci… Southern Quillw… EN 12 SPECIES 147368 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes georgi… Isoetes georgi… Georgia Quillwo… EN 13 SPECIES 1216603 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes granit… Isoetes granit… Flat Rock Quill… EN 14 SPECIES 144776 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes hawaii… Isoetes hawaii… Hawai`i Quillwo… EN 15 SPECIES 1216105 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes howell… Isoetes howell… Howell's Quillw… EN 16 SPECIES 147799 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes hyemal… Isoetes hyemal… Winter Quillwort EN 17 SPECIES 160975 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes juncif… Isoetes juncif… Rush Quillwort EN 18 SPECIES 738978 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes lacust… Isoetes lacust… Western Lake Qu… EN 19 SPECIES 1131640 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes lauren… Isoetes lauren… NA EN 20 SPECIES 147798 ELEMENT_G… /Taxon/ELE… PPISO0… Isoetes lithop… Isoetes lithop… Rock Quillwort EN # … with 6 more variables: roundedGRank , nations , lastModified , classificationStatus , # speciesGlobal , gRank $resultsSummary name value 1 page 0 2 recordsPerPage 20 3 totalPages 1662 4 totalResults 33226 5 species_total 33226 > ns_search_spp(species_taxonomy = list(scientificTaxonomy = "lepidoptera", level = "order")) Error: Internal Server Error (HTTP 500) > ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order")) Error: Internal Server Error (HTTP 500) > ns_search_spp function (text = NULL, text_adv = NULL, status = NULL, location = NULL, species_taxonomy = NULL, record_subtype = NULL, modified_since = NULL, page = NULL, per_page = NULL, ...) { paging <- handle_paging(page, per_page) text <- handle_text(text, text_adv) status <- handle_status(status) location <- handle_location(location) species_taxonomy <- handle_sptax(species_taxonomy) record_subtype <- handle_subtype(record_subtype) assert(modified_since, "character") res <- ns_POST(url = file.path(ns_base(), "api/data/speciesSearch"), body = list(criteriaType = "species", textCriteria = list(text) %|lst|% NULL, statusCriteria = list(status) %|lst|% NULL, locationCriteria = list(location) %|lst|% NULL, speciesTaxonomyCriteria = list(species_taxonomy) %|lst|% NULL, recordSubtypeCriteria = list(record_subtype) %|lst|% NULL, pagingOptions = paging, modifiedSince = modified_since), ...) parse_search(res) } > ns_base Error: object 'ns_base' not found > natserv:::ns_base() [1] "https://explorer.natureserve.org" > #next, download status classifications from natureserve > lep_stats <- ns_search_spp(species_taxonomy = list(scientificTaxonomy = "Lepidoptera", level = "order", kingdom = "Animalia")) Error: `species_taxonomy` must be a list w/ 'informalTaxonomy' or 'level' and 'scientificTaxonomy' > devtools::session_info() ─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 4.1.2 (2021-11-01) os macOS Monterey 12.1 system x86_64, darwin17.0 ui RStudio language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz America/New_York date 2022-01-18 rstudio 2021.09.0+351 Ghost Orchid (desktop) pandoc 2.17.0.1 @ /usr/local/bin/pandoc ─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────── package * version date (UTC) lib source assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0) backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.0) broom 0.7.11 2022-01-03 [1] CRAN (R 4.1.2) cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.0) callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0) cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.1.0) cli 3.1.0 2021-10-27 [1] CRAN (R 4.1.0) colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.0) conditionz 0.1.0 2019-04-24 [1] CRAN (R 4.1.0) crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.0) crul 1.2.0 2021-11-22 [1] CRAN (R 4.1.0) curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0) data.table 1.14.2 2021-09-27 [1] CRAN (R 4.1.0) DBI 1.1.2 2021-12-20 [1] CRAN (R 4.1.0) dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.1.0) desc 1.4.0 2021-09-28 [1] CRAN (R 4.1.0) devtools 2.4.3 2021-11-30 [1] CRAN (R 4.1.0) dplyr * 1.0.7 2021-06-18 [1] CRAN (R 4.1.0) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0) fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2) fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0) forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.1.0) fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.0) generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.0) ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.0) glue 1.6.0 2021-12-17 [1] CRAN (R 4.1.2) gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0) haven 2.4.3 2021-08-04 [1] CRAN (R 4.1.0) hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.0) httpcode 0.3.0 2020-04-10 [1] CRAN (R 4.1.0) httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0) jsonlite 1.7.3 2022-01-17 [1] CRAN (R 4.1.2) lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.1.0) lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0) lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.0) magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.1.0) modelr 0.1.8 2020-05-19 [1] CRAN (R 4.1.0) munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0) natserv * 1.0.0.91 2022-01-18 [1] Github (ropensci/natserv@72acf2e) oai 0.3.2 2021-05-13 [1] CRAN (R 4.1.0) patchwork * 1.1.1 2020-12-17 [1] CRAN (R 4.1.0) pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.0) pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.0) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0) pkgload 1.2.4 2021-11-30 [1] CRAN (R 4.1.0) plyr 1.8.6 2020-03-03 [1] CRAN (R 4.1.0) prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0) processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0) ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0) purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.1.0) R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0) Rcpp 1.0.8 2022-01-13 [1] CRAN (R 4.1.2) readr * 2.1.1 2021-11-30 [1] CRAN (R 4.1.0) readxl 1.3.1 2019-03-13 [1] CRAN (R 4.1.0) remotes 2.4.2 2021-11-30 [1] CRAN (R 4.1.0) reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0) rgbif * 3.6.0 2021-06-02 [1] CRAN (R 4.1.0) rlang 0.4.12 2021-10-18 [1] CRAN (R 4.1.0) rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0) rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0) rvest 1.0.2 2021-10-16 [1] CRAN (R 4.1.0) scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.0) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.0) stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.0) stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.0) testthat 3.1.1 2021-12-03 [1] CRAN (R 4.1.0) tibble * 3.1.6 2021-11-07 [1] CRAN (R 4.1.0) tidyr * 1.1.4 2021-09-27 [1] CRAN (R 4.1.0) tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0) tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.1.0) triebeard 0.3.0 2016-08-04 [1] CRAN (R 4.1.0) tzdb 0.2.0 2021-10-27 [1] CRAN (R 4.1.0) urltools 1.7.3 2019-04-14 [1] CRAN (R 4.1.0) usethis 2.1.5 2021-12-09 [1] CRAN (R 4.1.0) utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0) uuid 1.0-3 2021-11-01 [1] CRAN (R 4.1.0) vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0) wellknown 0.7.4 2021-05-25 [1] CRAN (R 4.1.0) whisker 0.4 2019-08-28 [1] CRAN (R 4.1.0) withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.0) wk 0.6.0 2022-01-03 [1] CRAN (R 4.1.2) xml2 1.3.3 2021-11-30 [1] CRAN (R 4.1.0) [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library ──────────────────────────────────────────────────────────────────────────────────────────────── ```
mikeroswell commented 2 years ago

Looks like it is overspecifying st in natserv:::handle_sptax

Suggest edit from current: if (!all(names(st) %in% c("level", "scientificTaxonomy", "informalTaxonomy"))) to if (!all(names(st) %in% c("level", "kingdom", "scientificTaxonomy", "informalTaxonomy")))

sckott commented 2 years ago

hi @mikeroswell - this pkg is looking for a new maintainer - are you interested?

maelle commented 2 years ago

This repository is about to be archived.