Skip to content

Commit 4a0b064

Browse files
committed
adding support for multiple taxnomy download
1 parent 000e420 commit 4a0b064

17 files changed

+162
-53
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Description: A programmatic interface to the Web Service methods
88
retrieving information on data providers, getting species occurrence
99
records, getting counts of occurrence records, and using the GBIF
1010
tile map service to make rasters summarizing huge amounts of data.
11-
Version: 3.8.4.4
11+
Version: 3.8.4.5
1212
License: MIT + file LICENSE
1313
Authors@R: c(
1414
person("Scott", "Chamberlain", role = "aut", comment = c("0000-0003-1444-9135")),

R/download_predicate_dsl.R

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#' @name download_predicate_dsl
44
#' @param key (character) the key for the predicate. See "Keys" below
55
#' @param value (various) the value for the predicate
6+
#' @param checklistKey (character) A checklistKey to use for downloading using
7+
#' alternative taxonomies. The default is `NULL`, which means the GBIF backbone
8+
#' taxonomy will be used.
69
#' @param ...,.list For `pred_or()` or `pred_and()`, one or more objects of
710
#' class `occ_predicate`, created by any `pred*` function
811
#' @section predicate methods and their equivalent types:
@@ -224,7 +227,7 @@
224227

225228
#' @rdname download_predicate_dsl
226229
#' @export
227-
pred <- function(key, value) pred_factory("=")(key, value)
230+
pred <- function(key, value, checklistKey = NULL) pred_factory("=")(key, value, checklistKey)
228231
#' @rdname download_predicate_dsl
229232
#' @export
230233
pred_gt <- function(key, value) pred_factory(">")(key, value)
@@ -302,10 +305,18 @@ print.occ_predicate_list <- function(x, ...) {
302305

303306
# helpers
304307
pred_factory <- function(type) {
305-
function(key, value) {
308+
function(key, value, checklistKey = NULL) {
306309
if (!length(key) == 1) stop("'key' must be length 1", call. = FALSE)
307310
if (!length(value) == 1) stop("'value' must be length 1", call. = FALSE)
308-
z <- parse_pred(key, value, type)
311+
if (!is.null(checklistKey)) {
312+
if (key != "taxonKey") {
313+
stop("`checklistKey` can only be used when `key` is 'taxonKey'", call. = FALSE)
314+
}
315+
if (!is_uuid(checklistKey)) {
316+
stop("`checklistKey` must be a valid UUID", call. = FALSE)
317+
}
318+
}
319+
z <- parse_pred(key, value, type, checklistKey)
309320
structure(z, class = "occ_predicate")
310321
}
311322
}
@@ -513,9 +524,10 @@ key_lkup <- list(
513524
INSTITUTION_KEY = "INSTITUTION_KEY"
514525
)
515526

516-
parse_pred <- function(key, value, type = "and") {
527+
parse_pred <- function(key, value, type = "and", checklistKey = NULL) {
517528
assert(key, "character")
518529
assert(type, "character")
530+
assert(checklistKey, "character")
519531

520532
ogkey <- key
521533
key <- key_lkup[[key]]
@@ -544,6 +556,13 @@ parse_pred <- function(key, value, type = "and") {
544556
list(type = unbox(type), parameter = unbox(key))
545557
} else if (type == "isNull") {
546558
list(type = unbox(type), parameter = unbox(key))
559+
} else if (type == "equals" & !is.null(checklistKey) & key == "TAXON_KEY") {
560+
list(
561+
type = unbox(type),
562+
key = unbox(key),
563+
value = unbox(as_c(value)),
564+
checklistKey = unbox(checklistKey)
565+
)
547566
} else {
548567
list(type = unbox(type), key = unbox(key), value = unbox(as_c(value)))
549568
}

man/download_predicate_dsl.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/occ_download.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/occ_download_1.yml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/occ_download_10.yml

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/occ_download_2.yml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/occ_download_3.yml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/occ_download_4.yml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/occ_download_5.yml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)