R/other_sources.R

Defines functions bindlist other_sources

Documented in other_sources

#' 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)))
}

Try the ritis package in your browser

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

ritis documentation built on Feb. 2, 2021, 9:06 a.m.