Skip to content

Commit

Permalink
name_lookup adding constituentKey #729
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnwllr committed May 1, 2024
1 parent 9078e0e commit 3ae007a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
54 changes: 42 additions & 12 deletions R/name_lookup.r
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,28 @@
#' curlopts = list(verbose = TRUE))
#' }

name_lookup <- function(query=NULL, rank=NULL, higherTaxonKey=NULL, status=NULL,
isExtinct=NULL, habitat=NULL, nameType=NULL, datasetKey=NULL,
origin=NULL, nomenclaturalStatus=NULL, limit=100, start=0, facet=NULL,
facetMincount=NULL, facetMultiselect=NULL, type=NULL, hl=NULL, issue=NULL,
verbose=FALSE, return=NULL, curlopts = list()) {
name_lookup <- function(query=NULL,
rank=NULL,
higherTaxonKey=NULL,
status=NULL,
isExtinct=NULL,
habitat=NULL,
nameType=NULL,
datasetKey=NULL,
origin=NULL,
nomenclaturalStatus=NULL,
limit=100,
start=0,
facet=NULL,
facetMincount=NULL,
facetMultiselect=NULL,
type=NULL,
hl=NULL,
issue=NULL,
constituentKey=NULL,
verbose=FALSE,
return=NULL,
curlopts = list()) {

pchk(return, "name_lookup")
if (!is.null(facetMincount) && inherits(facetMincount, "numeric"))
Expand All @@ -99,15 +116,28 @@ name_lookup <- function(query=NULL, rank=NULL, higherTaxonKey=NULL, status=NULL,
datasetKey <- as_many_args(datasetKey)
origin <- as_many_args(origin)
issue <- as_many_args(issue)
constituentKey <- as_many_args(constituentKey)

url <- paste0(gbif_base(), '/species/search')
args <- rgbif_compact(list(q=query, isExtinct=as_log(isExtinct),
nomenclaturalStatus=nomenclaturalStatus, limit=limit, offset=start,
facetMincount=facetMincount,
facetMultiselect=as_log(facetMultiselect), hl=as_log(hl),
type=type))
args <- c(args, facetbyname, rank, higherTaxonKey, status,
habitat, nameType, datasetKey, origin, issue)
args <- rgbif_compact(list(q=query,
isExtinct=as_log(isExtinct),
nomenclaturalStatus=nomenclaturalStatus,
limit=limit, offset=start,
facetMincount=facetMincount,
facetMultiselect=as_log(facetMultiselect),
hl=as_log(hl),
type=type))
args <- c(args,
facetbyname,
rank,
higherTaxonKey,
status,
habitat,
nameType,
datasetKey,
origin,
issue,
constituentKey)

# paging implementation
if (limit > 1000) {
Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/namelkup.r
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
#' @param limit Number of records to return.
#' Hard maximum limit set by GBIF API: 99999.
#' @param start Record number to start at. Default: 0.
#' @param constituentKey Filters by the dataset's constituent key (a uuid).
#' @param verbose (logical) If \code{TRUE}, all data is returned as a list for each
#' element. If \code{FALSE} (default) a subset of the data that is thought to be most
#' essential is organized into a data.frame.
#'
#' @param return Defunct. All components are returned; index to the
#' one(s) you want
#'
Expand Down
3 changes: 3 additions & 0 deletions man/name_lookup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/testthat/test-name_lookup.r
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ test_that("paging: name_usage returns all records from dataset: limit > n_record
expect_gte(nrow(cc$data), 1051)
})

test_that("name_lookup constituentKey works as expected.", {

vcr::use_cassette("name_lookup_constituentKey", {
aa <- name_lookup(constituentKey = "7ddf754f-d193-4cc9-b351-99906754a03b")
}, preserve_exact_body_bytes = TRUE)

expect_is(aa, "gbif")
expect_is(aa$data, "data.frame")
expect_is(aa$data, "tbl_df")
expect_is(aa$data, "tbl")
expect_equal(unique(tolower(aa$data$constituentKey)), "7ddf754f-d193-4cc9-b351-99906754a03b")
})


test_that("name_lookup handles no results without failing", {
skip_on_cran() # because fixture in .Rbuildignore

Expand Down

0 comments on commit 3ae007a

Please sign in to comment.