You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R robis包获取多分类ID物种全部OBIS分布记录的方法问询

解决方案核心逻辑

occurrence()函数传入学名时默认仅匹配优先级最高的单个分类ID,不会自动关联所有同学名的不同分类条目。你可以先通过robis内置的taxa()函数查询目标学名对应的所有有效aphiaID,再将全部ID传入occurrence()拉取全量记录。

单物种实现代码

library(robis)
library(dplyr)

# 目标物种学名
target_sci <- "Ceramium virgatum"

# 第一步:查询该学名对应的所有OBIS分类ID
taxon_list <- taxa(scientificname = target_sci)
all_aphia_id <- unique(taxon_list$aphiaID)

# 第二步:拉取所有ID对应的全量分布记录
full_occur <- occurrence(taxonid = all_aphia_id)

# 校验结果
full_occur %>% 
  group_by(aphiaID) %>%
  summarise(
    记录数 = n(),
    对应学名 = unique(scientificName)
  )

多物种批量处理代码

如果需要处理多个物种,可以封装为自定义函数批量执行:

library(purrr)

# 自定义安全拉取函数,处理无匹配ID的异常情况
pull_full_obis <- function(sci_name) {
  taxon_res <- taxa(scientificname = sci_name)
  if (nrow(taxon_res) == 0) {
    warning(paste("物种", sci_name, "未查询到匹配的OBIS分类ID"))
    return(tibble())
  }
  ids <- unique(taxon_res$aphiaID)
  return(occurrence(taxonid = ids))
}

# 你的物种学名列表,替换为实际数据即可
sci_name_list <- c("Ceramium virgatum", "示例物种1", "示例物种2")

# 批量拉取所有物种的全量记录,合并为单个数据框
all_species_data <- map_dfr(sci_name_list, pull_full_obis)

内容的提问来源于stack exchange,提问作者Jake L

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 20:06:01