File: api-tnrs.R

package info (click to toggle)
r-cran-rotl 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,384 kB
  • sloc: sh: 9; makefile: 5
file content (67 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
##' @importFrom jsonlite unbox
##' @importFrom httr content
## Match taxon names
.tnrs_match_names <- function(names = NULL, context_name = NULL,
                              do_approximate_matching = TRUE,
                              ids = NULL, include_suppressed = FALSE, ...) {
  if (is.null(names)) {
    stop("You must supply a ", sQuote("names"), " argument")
  } else if (!is.character(names)) {
    stop(
      "Argument ", sQuote("names"), " must be of class ",
      sQuote("character")
    )
  }
  if (!is.null(ids)) {
    if (length(ids) != length(names)) {
      stop(
        "Arguments ", sQuote("ids"), " and ",
        sQuote("names"), " must be of the same length"
      )
    } else if (!is.character(ids)) {
      stop(
        "Argument ", sQuote("ids"), " must be of class ",
        sQuote("character")
      )
    }
  }
  check_is_flag(do_approximate_matching)
  check_is_flag(include_suppressed)

  if (!is.null(context_name)) {
    check_is_string(context_name)    
    context_name <- jsonlite::unbox(context_name)
  }

  q <- list(
    names = names, context_name = context_name,
    do_approximate_matching = jsonlite::unbox(do_approximate_matching),
    ids = ids, include_suppressed = jsonlite::unbox(include_suppressed)
  )
  toKeep <- sapply(q, is.null)
  q <- q[!toKeep]

  res <- otl_POST("tnrs/match_names", body = q, ...)
  res
}


##' @importFrom httr content
## Get OpenTree TNRS contexts
.tnrs_contexts <- function(...) {
  res <- otl_POST("tnrs/contexts", body = list(), ...)
  res
}


## Infer taxonomic context from a set of names
.tnrs_infer_context <- function(names = NULL, ...) {
  if (is.null(names)) {
    stop("Must supply a \'names\' argument")
  } else if (!is.character(names)) {
    stop("Argument \'names\' must be of class \"character\"")
  }
  q <- list(names = names)
  res <- otl_POST("tnrs/infer_context", body = q, ...)
  res
}