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

R语言使用biomaRt包调用useEnsembl时触发collect()错误的求助

解决biomaRt调用useEnsembl时的collect()参数错误

问题重现

运行以下代码时触发报错:

library(biomaRt)
ensembl <- useEnsembl(biomart = "ensembl", dataset = "hsapiens_gene_ensembl")

环境信息:

  • R版本:4.3.1 (2023-06-16 ucrt)
  • BiomaRt版本:2.58.0
  • 操作系统:Windows
  • 已尝试更新biomaRt和dbplyr包并重启R,问题未解决

报错信息:

Error in `collect()`:
! Failed to collect lazy table.
Caused by error in `db_collect()`:
! Arguments in `...` must be used.
✖ Problematic argument:
• ..1 = Inf
ℹ Did you misspell an argument name?

Backtrace:
     ▆
  1. ├─biomaRt::useEnsembl(biomart = "genes", dataset = "hsapiens_gene_ensembl")
  2. │ └─biomaRt:::.getEnsemblSSL()
  3. │   └─BiocFileCache::BiocFileCache(cache, ask = FALSE)
  4. │     └─BiocFileCache:::.sql_create_db(bfc)
  5. │       └─BiocFileCache:::.sql_validate_version(bfc)
  6. │         └─BiocFileCache:::.sql_schema_version(bfc)
  7. │           ├─base::tryCatch(...)
  8. │           │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  9. │           └─tbl(src, "metadata") %>% collect(Inf)
 10. ├─dplyr::collect(., Inf)
 11. └─dbplyr:::collect.tbl_sql(., Inf)
 12.   ├─base::tryCatch(...)
 13.   │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 14.   │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 15.   │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 16.   └─dbplyr::db_collect(x$src$con, sql, n = n, warn_incomplete = warn_incomplete, ...)`

报错分析

从回溯信息看,错误根源在于BiocFileCache包内部调用collect(Inf)时,新版dbplyr(v2.3.0+)不再允许将Inf作为位置参数传递,要求显式指定n=Inf。这是BiocFileCache与dbplyr版本不兼容导致的问题。

解决方案

1. 更新BiocFileCache包

BiocFileCache的后续版本已修复该参数传递问题,优先更新到最新版:

# 若使用BiocManager管理生物信息学包
if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("BiocFileCache")

# 或直接用CRAN安装
install.packages("BiocFileCache")

更新完成后重启R,重新运行代码。

2. 清除BiocFileCache缓存

旧缓存数据库可能存在损坏,导致版本验证失败,清除缓存后重试:

library(BiocFileCache)
# 获取当前缓存对象
bfc <- BiocFileCache()
# 清除所有缓存文件
bfcpurge(bfc, ask = FALSE)

重启R后再次调用useEnsembl。

3. 指定独立缓存目录

避免使用默认缓存路径,临时指定一个新的缓存目录,绕过旧缓存问题:

ensembl <- useEnsembl(
    biomart = "ensembl", 
    dataset = "hsapiens_gene_ensembl",
    cache = tempdir()  # 使用系统临时目录作为缓存
)

4. 降级dbplyr到兼容版本

若更新BiocFileCache无效,可尝试降级dbplyr到v2.2.0(该版本仍支持位置参数传递):

install.packages("dbplyr", version = "2.2.0", repos = "http://cran.us.r-project.org")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 11:43:15