File: kingdoms.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 (32 lines) | stat: -rw-r--r-- 960 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
31
32
#' Get kingdom names from tsn
#'
#' @export
#' @name kingdoms
#' @inheritParams accepted_names
#' @template tsn
#' @details
#' \itemize{
#'  \item kingdom_name: Get kingdom name for a TSN
#'  \item kingdom_names: Get all possible kingdom names
#' }
#' @examples \dontrun{
#' kingdom_name(202385)
#' kingdom_name(202385, wt = "xml")
#' kingdom_names()
#' }
kingdom_name <- function(tsn, wt = "json", raw = FALSE, ...) {
  out <- itis_GET("getKingdomNameFromTSN", list(tsn = tsn), wt, ...)
  if (raw || wt == "xml") return(out)
  res <- tc(pick_cols(parse_raw(out), c('kingdomid', 'kingdomname', 'tsn')))
  tibble::as_tibble(
    if (length(names(res)) != 1) res else NULL
  )
}

#' @export
#' @rdname kingdoms
kingdom_names <- function(wt = "json", raw = FALSE, ...) {
  out <- itis_GET("getKingdomNames", list(), wt, ...)
  if (raw || wt == "xml") return(out)
  pick_cols(tibble::as_tibble(parse_raw(out)$kingdomNames), c('kingdomid', 'kingdomname', 'tsn'))
}