无法使用 R 中 rgbif 包的 occ_search 函数获取发生数据

Unable to fetch Occurrence Data using occ_search function of rgbif package in R

我正在尝试从 rgbif R 包中获取 class = Mammalia 的记录。首先,我尝试了 usageKey:

key <- name_backbone(name = "Mammalia")

成功返回了usageKey

然后我尝试使用 occ_search 并收到以下错误:

occ_search(taxonKey = key, limit = 20)

Error: Invalid integer range: Mammalia

occ_search(taxonKey = key, limit = 10)

Error: Invalid integer range: Mammalia

有人可以帮我解决这个问题吗?

您在使用 key 时遗漏了一个非常小的细节。请注意,您的变量 key 是一个列表。要将其用作 taxonKey,您需要通过 $ 运算符访问它。这是我得到的:

library(rgbif)
key <- name_backbone(name = "Mammalia")
key$usageKey
## [1] 359

或者,使用双括号运算符 ([[]]):

key[[1]]
## [1] 359

现在,您应该可以毫无问题地访问分类信息:

occ_search(taxonKey = key$usageKey, limit = 20)

## Records found [10730158] 
## Records returned [20] 
## No. unique hierarchies [3] 
## No. media records [1] 
## No. facets [0] 
## Args [taxonKey=359, limit=20, offset=0, fields=all] 
## # A tibble: 20 × 61
##           name        key decimalLatitude decimalLongitude issues
##          <chr>      <int>           <dbl>            <dbl>  <chr>
## 1    Lynx lynx 1424727732        63.43489         9.950017 gass84
## 2  Canis lupus 1425221384        60.65852        12.068240 gass84
## (more records omitted)

希望对您有所帮助。