File: other_sources.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 (31 lines) | stat: -rw-r--r-- 901 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
#' Returns a list of the other sources used for the TSN.
#'
#' @export
#' @inheritParams accepted_names
#' @template tsn
#' @examples \dontrun{
#' # results
#' other_sources(tsn=182662)
#' # no results
#' other_sources(tsn=2085272) 
#' # get xml
#' other_sources(tsn=182662, wt = "xml")
#' }
other_sources <- function(tsn, wt = "json", raw = FALSE, ...) {
  out <- itis_GET("getOtherSourcesFromTSN", list(tsn = tsn), wt, ...)
  if (raw || wt == "xml") return(out)
  x <- parse_raw(out)$otherSources
  if (inherits(x, "logical") || is.null(x)) {
    tibble::tibble()
  } else {
    x <- cbind(dr_op(x, "referencefor"), bindlist(x$referenceFor))
    tibble::as_tibble(pick_cols(
      x,
      c("acquisitiondate","name","referredtsn","source", "sourcetype","updatedate","version")
    ))
  }
}

bindlist <- function(x) {
  (data.table::setDF(data.table::rbindlist(x, use.names = TRUE, fill = TRUE)))
}