ropensci/natserv

Feature request: query by subnation and subnational status

Closed this issue · 3 comments

Imagine I'd like to see the state conservation status for all species from one genus of bee (Andrena) in Maryland.

Ideally I'd query something like the below (sure, I could specify my search for genus better, not the point here):

ns_search_spp(text_adv = list(searchToken = "Andrena"
                                        , matchAgainst = "scientificName"
                                        , operator = "contains")
 , location = list(nation = "US", subnation = "MD"))

However, this returns a terribly complicated result that includes the status for each species that matches the search in each nation and subnation in which the status has been recorded. I'd love to see functionality to filter the results to something more streamlined and specific! Happy to discuss more, thanks!

My workaround "unnest" some of the lists in the tibble result, then filter:

library(tidyverse)
unnested <- ns_search_spp(text_adv = list(searchToken = "Andrena"
                                        , matchAgainst = "scientificName"
                                        , operator = "contains")
                        , location = list(nation = "US", subnation = "MD"))[[1]] %>% 
  unnest(cols = nations) %>% 
  unnest(cols = "subnations", names_repair = "unique") %>% 
  filter(subnationCode == "MD")
unnested

Sorry for delay, was on leave.

While I understand the need here for your use case, I'm not sure this would be a general use that most people would have - i.e., not sure it would warrant including a function in this package to achieve this. Thoughts?

This repository is about to be archived.