今天在安装ComplexHeatmap时使用如下命令出现报错:
>install.packages("ComplexHeatmap", type = "source")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
https://cran.rstudio.com/bin/windows/Rtools/
将程序包安装入‘C:/Users/86150/AppData/Local/R/win-library/4.3’
(因为‘lib’没有被指定)
Warning in install.packages :
package ‘ComplexHeatmap’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
这是因为没有安装rtool所以才会报错。
解决方法:下载安装对应版本的Rtools
1、下载对应版本的Rtools
查看自己安装的R版本---Rtools
> R.version.string
[1] "R version 4.3.2 (2023-10-31 ucrt)"
这里显示自己的安装的版本R是R4.3.2
RTools: Toolchains for building R and R packages from source on Windows
2.按照指示进行安装
3. BiocManage安装ComplexHeatmap
当我在使用install.packages()安装ComplexHeatmap出现了该包对于我的R版本(4.3.1)不可用,如下:
Warning in install.packages : package ‘ComplexHeatmap’ is not available for this version of R A version of this package for your version of R might be available elsewhere, see the ideas at https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
尝试换源无果后,便想到使用BiocManager来安装ComplexHeatmap,由于是新电脑所以需要安装它,安装成功之后可以使用检查版本的命令来确认是否安装成功,运行后会输出其对应的版本。
# install command
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
# check command
BiocManager::version()
安装成功之后,便使用BiocManager的install功能,::两个冒号是R语言中调用指定包下功能时引导符,类似于python中.方法。运行下面的代码,开始安装ComplexHeatmap包。
BiocManager::install("ComplexHeatmap")
在安装过程中出现了有些包需要更新的情况,向你询问update all/some/none
,建议全部更新。如果使用BiocManager::install("ComplexHeatmap")
安装出现版本不符的情况可以运行下面的代码强制安装。
BiocManager::install("ComplexHeatmap", force=TRUE)
当包安装成功之后使用library(ComplexHeatmap),提示缺少S4Vector依赖包,按照之前介绍的解决方法,使用install.packages()安装缺少的依赖包即可,但是当我使用intall.packages('S4vector')安装时又出现了版本冲突的问题。
于是便尝试了再次使用BiocManager
去安装对应的依赖包,成功解决。
BiocManager::install("S4Vector")
参考来源: