R/nbn_classification.R

Defines functions nbn_GET_2 nbn_classification

Documented in nbn_classification

#' Search UK National Biodiversity Network database for
#' taxonomic classification
#'
#' @export
#' @param id (character) An NBN identifier.
#' @param ... Further args passed on to [crul::verb-GET]
#' @return A data.frame
#' @family nbn
#' @author Scott Chamberlain, 
#' @references https://api.nbnatlas.org/
#' @examples \dontrun{
#' nbn_classification(id="NHMSYS0000376773")
#'
#' # get id first, then pass to this fxn
#' id <- get_nbnid("Zootoca vivipara", rec_only = TRUE, rank = "Species")
#' nbn_classification(id)
#'
#' nbn_classification(id="NHMSYS0000502940", verbose = TRUE)
#' }
nbn_classification <- function(id, ...) {
  url <- file.path(nbn_base(), "classification", id)
  nbn_GET_2(url, ...)
}

nbn_GET_2 <- function(url, ...) {
  cli <- crul::HttpClient$new(url, headers = tx_ual, opts = list(...))
  res <- cli$get()
  res$raise_for_status()
  nmslwr(jsonlite::fromJSON(res$parse("UTF-8"), TRUE))
}

Try the taxize package in your browser

Any scripts or data that you put into this service are public.

taxize documentation built on Sept. 11, 2024, 6:13 p.m.