ropensci/natserv

Unable to run R scripts on Nature Serve API

Opened this issue · 3 comments

Session Info
Hey folks, I'm trying to obtain unique IDs for a csv of taxa. This is my test code using only canis lupis initially: # Install and load the devtools package (if not already installed) if (!requireNamespace("devtools", quietly = TRUE)) { install.packages("devtools") } library(devtools)

Install and load the natserv package from GitHub (if not already installed)

if (!requireNamespace("natserv", quietly = TRUE)) {
devtools::install_github("ropensci/natserv")
}
library(natserv)

gray.wolf.search <- ns_search_spp(x = "Canis lupus")
gray.wolf.search$globalSpeciesUid

Over repeated attempts I am consistently receiving a NULL output. I queried nature serve using postman via their example: explorer.natureserve.org/api/data/taxon/ELEMENT_GLOBAL.2.154701 HTTP/1.1
?Accept=application/json, just to see if I could get anything back, but it resulted in an internal server error code 500.

Is there something wrong with my code/query, or does this have something to do with Nature Serve servers being down?
Thanks!

Hi @mokezonline
Apologies for the delay in getting back to you. I believe that this is a code issue, as I noticed a few inconsistences in your example script. Here's my corrected version:

library(natserv)
gray.wolf.search <- ns_search_spp(text="Canis lupus")
gray.wolf.search$results$uniqueId

In the second line, you need to replace "x" with "text". Interestingly the code returns a set of 20 results if "text" is missing. I'm not sure if that's the expected behavior or not.

In the third line, you're missing the "results" part of the list object. Also the variable with the UID is 'uniqueId' not 'globalSpeciesUid.

Let me know if this helps. Also, I heard you also emailed NatureServe with a version of this question. I'll let my colleagues know that we hopefully solved it here.