Skip to content

Commit 3ae007a

Browse files
authored
name_lookup adding constituentKey #729
1 parent 9078e0e commit 3ae007a

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

R/name_lookup.r

+42-12
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,28 @@
7575
#' curlopts = list(verbose = TRUE))
7676
#' }
7777

78-
name_lookup <- function(query=NULL, rank=NULL, higherTaxonKey=NULL, status=NULL,
79-
isExtinct=NULL, habitat=NULL, nameType=NULL, datasetKey=NULL,
80-
origin=NULL, nomenclaturalStatus=NULL, limit=100, start=0, facet=NULL,
81-
facetMincount=NULL, facetMultiselect=NULL, type=NULL, hl=NULL, issue=NULL,
82-
verbose=FALSE, return=NULL, curlopts = list()) {
78+
name_lookup <- function(query=NULL,
79+
rank=NULL,
80+
higherTaxonKey=NULL,
81+
status=NULL,
82+
isExtinct=NULL,
83+
habitat=NULL,
84+
nameType=NULL,
85+
datasetKey=NULL,
86+
origin=NULL,
87+
nomenclaturalStatus=NULL,
88+
limit=100,
89+
start=0,
90+
facet=NULL,
91+
facetMincount=NULL,
92+
facetMultiselect=NULL,
93+
type=NULL,
94+
hl=NULL,
95+
issue=NULL,
96+
constituentKey=NULL,
97+
verbose=FALSE,
98+
return=NULL,
99+
curlopts = list()) {
83100

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

103121
url <- paste0(gbif_base(), '/species/search')
104-
args <- rgbif_compact(list(q=query, isExtinct=as_log(isExtinct),
105-
nomenclaturalStatus=nomenclaturalStatus, limit=limit, offset=start,
106-
facetMincount=facetMincount,
107-
facetMultiselect=as_log(facetMultiselect), hl=as_log(hl),
108-
type=type))
109-
args <- c(args, facetbyname, rank, higherTaxonKey, status,
110-
habitat, nameType, datasetKey, origin, issue)
122+
args <- rgbif_compact(list(q=query,
123+
isExtinct=as_log(isExtinct),
124+
nomenclaturalStatus=nomenclaturalStatus,
125+
limit=limit, offset=start,
126+
facetMincount=facetMincount,
127+
facetMultiselect=as_log(facetMultiselect),
128+
hl=as_log(hl),
129+
type=type))
130+
args <- c(args,
131+
facetbyname,
132+
rank,
133+
higherTaxonKey,
134+
status,
135+
habitat,
136+
nameType,
137+
datasetKey,
138+
origin,
139+
issue,
140+
constituentKey)
111141

112142
# paging implementation
113143
if (limit > 1000) {

man-roxygen/namelkup.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
#' @param limit Number of records to return.
8787
#' Hard maximum limit set by GBIF API: 99999.
8888
#' @param start Record number to start at. Default: 0.
89+
#' @param constituentKey Filters by the dataset's constituent key (a uuid).
8990
#' @param verbose (logical) If \code{TRUE}, all data is returned as a list for each
9091
#' element. If \code{FALSE} (default) a subset of the data that is thought to be most
9192
#' essential is organized into a data.frame.
92-
#'
9393
#' @param return Defunct. All components are returned; index to the
9494
#' one(s) you want
9595
#'

man/name_lookup.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-name_lookup.r

+14
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ test_that("paging: name_usage returns all records from dataset: limit > n_record
146146
expect_gte(nrow(cc$data), 1051)
147147
})
148148

149+
test_that("name_lookup constituentKey works as expected.", {
150+
151+
vcr::use_cassette("name_lookup_constituentKey", {
152+
aa <- name_lookup(constituentKey = "7ddf754f-d193-4cc9-b351-99906754a03b")
153+
}, preserve_exact_body_bytes = TRUE)
154+
155+
expect_is(aa, "gbif")
156+
expect_is(aa$data, "data.frame")
157+
expect_is(aa$data, "tbl_df")
158+
expect_is(aa$data, "tbl")
159+
expect_equal(unique(tolower(aa$data$constituentKey)), "7ddf754f-d193-4cc9-b351-99906754a03b")
160+
})
161+
162+
149163
test_that("name_lookup handles no results without failing", {
150164
skip_on_cran() # because fixture in .Rbuildignore
151165

0 commit comments

Comments
 (0)