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

使用biomaRt时遇mutate()与dplyr::select()错误求助

biomaRt调用getBM时出现dplyr语法错误的解决方法

问题详情

使用biomaRt包获取Ensembl注释信息时,调用getBM()出现异常错误,重新加载包无法解决。

运行代码及报错

> library("biomaRt")
> # release 88 of Ensembl is March 2017
> ensembl <- useEnsembl(biomart = "ensembl", 
+                       dataset = "hsapiens_gene_ensembl", 
+                       mirror = "useast")
> annot2 <- getBM(attributes=c('ensembl_gene_id', 'chromosome_name', 'start_position', 'end_position', 'description', 'strand','external_gene_name'), 
+                 #filters ='ensembl_gene_id', 
+                 #values = gene_ids, 
+                 mart = ensembl)
Error in `mutate()`:
! Problem while computing `rpath = unname(bfcrpath(x, rids = rids))`.
Caused by error in `dplyr::select()`:
! <text>:1:7: unexpected symbol
1: Using an
          ^
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/dplyr:::mutate_error>
Error in `mutate()`:
! Problem while computing `rpath = unname(bfcrpath(x, rids = rids))`.
Caused by error in `dplyr::select()`:
! <text>:1:7: unexpected symbol
1: Using an
          ^
---
Backtrace:
  1. biomaRt::getBM(...)
22. dplyr:::select.data.frame(., rid, field)

环境信息

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.3.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] biomaRt_2.46.3      BiocManager_1.30.20 dplyr_1.0.9        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9           dbplyr_2.2.1         pillar_1.8.1         compiler_4.0.3       prettyunits_1.1.1    progress_1.2.2       tools_4.0.3         
 [8] bit_4.0.5            BiocFileCache_1.14.0 RSQLite_2.2.15       memoise_2.0.1        lifecycle_1.0.1      tibble_3.1.7         pkgconfig_2.0.3     
[15] rlang_1.0.4          DBI_1.1.3            cli_3.4.0            rstudioapi_0.14      curl_5.0.0           parallel_4.0.3       xfun_0.31           
[22] fastmap_1.1.1        withr_2.5.0          xml2_1.3.3           httr_1.4.5           stringr_1.4.1        rappdirs_0.3.3       askpass_1.1         
[29] hms_1.1.2            IRanges_2.24.1       generics_0.1.3       vctrs_0.4.1          S4Vectors_0.28.1     stats4_4.0.3         bit64_4.0.5         
[36] tidyselect_1.2.0     glue_1.6.2           Biobase_2.50.0       R6_2.5.1             fansi_1.0.3          AnnotationDbi_1.52.0 XML_3.99-0.13       
[43] limma_3.46.0         purrr_0.3.4          blob_1.2.3           magrittr_2.0.3       ellipsis_0.3.2       BiocGenerics_0.36.1  assertthat_0.2.1    
[50] utf8_1.2.3           tinytex_0.44         stringi_1.7.6        openssl_2.0.3        cachem_1.0.6         crayon_1.5.2        

解决步骤

这个错误源于BiocFileCache处理缓存元数据时的解析异常,可按以下顺序尝试解决:

  • 清除缓存
    删除现有BiocFileCache缓存文件,让包重新生成:

    library(BiocFileCache)
    bfc <- BiocFileCache()
    bfcpurge(bfc, ask = FALSE)
    

    执行后重新运行你的biomaRt代码。

  • 指定新缓存目录
    若清除缓存无效,手动指定一个新的可读写目录作为缓存路径:

    Sys.setenv("BIOCFILECACHE_DIR" = "/your/new/cache/path")
    

    替换路径后重启R再运行代码。

  • 更新兼容包版本
    当前R版本4.0.3对应Bioconductor 3.12,dplyr 1.0.9与部分旧版Bioconductor包可能存在兼容问题,更新相关包:

    BiocManager::install(c("BiocFileCache", "biomaRt"), update = FALSE)
    
  • 直接指定Ensembl版本
    调用Ensembl 88时,直接用version参数指定而非依赖镜像,避免镜像连接问题:

    ensembl <- useEnsembl(biomart = "ensembl", 
                           dataset = "hsapiens_gene_ensembl", 
                           version = 88)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 12:45:17