前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Bioconductor 中的 R 包安装教程(续一)

Bioconductor 中的 R 包安装教程(续一)

作者头像
章鱼猫先生
发布2021-11-26 15:00:09
6.9K0
发布2021-11-26 15:00:09
举报
文章被收录于专栏:BioIT爱好者

这是《Bioconductor 中的 R 包安装教程》的第二篇,完整的文章可以点击阅读原文查阅。

安装新版本的 Bioconductor R 包

Bioconductor 是与特定版本的 R 绑定的,正常来说当 Bioconductor 的包都来自同一版本时,它们的效果最佳。

Bioconductor versions are associated with specific R versions, as summarized here. Attempting to install a version of Bioconductor that is not supported by the version of R in use leads to an error; using the most recent version of Bioconductor may require installing a new version of R. From:https://cran.r-project.org/web/packages/BiocManager/vignettes/BiocManager.html

所以,当有些 R 包是基于高版本的 Bioconductor 开发的,在低版本的 Bioconductor/R 中直接执行BiocManager::install("package"),安装得到的 package 版本默认是与当前版本 Bioconductor/R 相匹配的,而并非是最新的版本。

DiffBind 包为例,DiffBind==3.4.0 是基于 Bioconductor==3.14(对应 R-4.1)开发的;我们在 Bioconductor==3.13(对应 R-4.0)中执行BiocManager::install("DiffBind"),默认安装的是 DiffBind==3.0.15

1. 源码方式安装

如果想要在 Bioconductor==3.13(对应 R-4.0)中安装 DiffBind==3.4.0,可以直接通过源码包的方式安装:

代码语言:javascript
复制
> packageurl <- "http://bioconductor.org/packages/release/bioc/src/contrib/DiffBind_3.4.0.tar.gz"
> install.packages(packageurl, repos=NULL, type="source")

2. BiocInstaller 安装

我们以在 R-3.4(Bioconductor==3.6)中安装最新版本的 clusterProfiler 为例。 在 Aanconda2 环境 R==3.4.3 中安装 clusterProfiler,发现package ‘clusterProfile’ is not available (for R version 3.4.3)

代码语言:javascript
复制
> source("https://bioconductor.org/biocLite.R")
Bioconductor version 3.6 (BiocInstaller 1.28.0), ?biocLite for help
A new version of Bioconductor is available after installing the most recent
  version of R; see http://bioconductor.org/install
> biocLite("clusterProfile")
BioC_mirror: https://bioconductor.org
Using Bioconductor 3.6 (BiocInstaller 1.28.0), R 3.4.3 (2017-11-30).
Installing package(s) ‘clusterProfile’
Old packages: 'ade4', 'ape', 'backports', 'caret', ......

Update all/some/none? [a/s/n]: n
Warning message:
package ‘clusterProfile’ is not available (for R version 3.4.3)

使用 BiocInstaller 安装 clusterProfiler

代码语言:javascript
复制
> source("https://bioconductor.org/biocLite.R")
Bioconductor version 3.6 (BiocInstaller 1.28.0), ?biocLite for help
A new version of Bioconductor is available after installing the most recent
  version of R; see http://bioconductor.org/install

> BiocInstaller::biocLite("clusterProfiler")
BioC_mirror: https://bioconductor.org
Using Bioconductor 3.6 (BiocInstaller 1.28.0), R 3.4.3 (2017-11-30).
Installing package(s) ‘clusterProfiler’
trying URL 'https://bioconductor.org/packages/3.6/bioc/src/contrib/clusterProfiler_3.6.0.tar.gz'
Content type 'application/x-gzip' length 4478098 bytes (4.3 MB)
==================================================
downloaded 4.3 MB

* installing *source* package ‘clusterProfiler’ ...
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (clusterProfiler)

> packageVersion('clusterProfiler')
[1] ‘3.6.0’

install.packages 一站式方案

install.packages来安装 CRAN 和 Bioconductor 所有的包!这是来自于 Y 叔 2018-09-25 在公众号发表的《不用 biocLite 安装 Bioconductor 包》介绍的方法。这里截取部分内容介绍一下。

用 install.packages 来安装 CRAN 和 Bioconductor 所有的包,你要做的很简单,在 ~/.Rprofile 里加入以下两行内容。

代码语言:javascript
复制
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")
utils::setRepositories(ind=1:2)

第一行,使用国内的镜像,我这里用的是清华大学的,第二行,设定 install.packages 从 CRAN 和 Bioconductor 中搜索包,其实你还可以让它支持比如 R-Forge 以及各种第三方的仓库。 然后你就可以愉快地使用 install.packages 来安装 Bioconductor 包了。

安装体积比较大的 R 包

安装 CRAN 或者 Bioconductor 中一些体积比较大的 R 包,如果网络不太好,经常可能会出现包下载不完(Timeout of 60 seconds was reached),从而导致无法正常安装。

参考 How do i set a timeout for utils::download.file() in R - Stack Overflow,增加 timeout 时长的同时使用国内的镜像进行加速:

代码语言:javascript
复制
getOption('timeout')
# [1] 60

options(timeout=100)

以上,就是这一次 Bioconductor R 包安装和使用的全部内容,希望对大家有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-11-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 BioIT爱好者 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装新版本的 Bioconductor R 包
    • 1. 源码方式安装
      • 2. BiocInstaller 安装
      • install.packages 一站式方案
      • 安装体积比较大的 R 包
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档