File: accepted_names.R

package info (click to toggle)
r-cran-ritis 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,156 kB
  • sloc: sh: 13; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#' Get accepted names from tsn
#'
#' @export
#' @param wt (character) One of "json" or "xml". Required.
#' @param raw (logical) Return raw JSON or XML as character string. Required.
#' Default: `FALSE`
#' @param ... curl options passed on to [crul::HttpClient]
#' @template tsn
#' @return Zero row data.frame if the name is accepted, otherwise a data.frame
#' with information on the currently accepted name
#' @examples \dontrun{
#' # TSN accepted - good name, empty data.frame returned
#' accepted_names(tsn = 208527)
#'
#' # TSN not accepted - input TSN is old name, non-empty data.frame returned
#' accepted_names(tsn = 504239)
#'
#' # raw json
#' accepted_names(tsn = 208527, raw = TRUE)
#' }
accepted_names <- function(tsn, wt = "json", raw = FALSE, ...) {
  out <- itis_GET("getAcceptedNamesFromTSN", list(tsn = tsn), wt, ...)
  if (raw || wt == "xml") return(out)
  tmp <- parse_raw(out)
  if (all(is.na(tmp$acceptedNames))) {
    tibble::tibble()
  } else {
    dr_op(tibble::as_tibble(tmp$acceptedNames), "class")
  }
}