为什么要安装老版本的包

为了应用R版本更新带来的效率提升和bug消除,我将服务器上的R升级到了最新版本(当前为4.1),然后在使用一些包的时候就会出现

Warning message:
“package ‘clusterProfiler’ is not available for this version of R

或者

Warning message:
“package ‘EnrichmentBrowser’ is not available for this version of R
Warning message:
“package ‘qvalue’ is not available for this version of R

这样的错误,这是由于clusterProfiler或者EnrichmentBrowser,qvalue没有跟的上R的更新步伐,如果需要在新版本上使用的话,必须要使用一些特别的安装手段

通过源码安装

大部分时候这是最稳定的方式,虽然无法通过R的命令直接安装,但是可以通过下载源码的方式安装。比如qvalue

  1. 首先下载安装包 在(bioconductor](https://bioconductor.org)找到qvalue的安装包下载地址进行下载
wget https://bioconductor.org/packages/release/bioc/src/contrib/qvalue_2.26.0.tar.gz
  1. 安装 直接在shell上调用R的安装命令
R CMD INSTALL qvalue_2.26.0.tar.gz 

顺利的话就会有正确安装的提示

* installing to library ‘/home/teng/R/x86_64-pc-linux-gnu-library/4.1’
* installing *source* package ‘qvalue’ ...
** using staged installation
** 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 from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (qvalue)

成功安装qvalue

同理可以依次安装其他的依赖包 最终安装好clusterProfiler

R CMD INSTALL   clusterProfiler_4.2.2.tar.gz 
* installing to library ‘/home/teng/R/x86_64-pc-linux-gnu-library/4.1’
* installing *source* package ‘clusterProfiler’ ...
** using staged installation
** 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 from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (clusterProfiler)

总结

本文介绍了如何在最新版本的R上安装各类软件包,由于R的安装方式与python不同,用最新版的R需要安装很多的依赖,这次我就下载了几十个源码并一个个进行安装,如果不想折腾的话还是选择老的R版本好了,3.5,3.6目前来说安装各类包最方便,推荐大家使用。