一、CRAN安装R包:install.packages()函数
1、单个包的安装:install.packages("ggplot2")
-
第一种
> install.packages("ggplot2")
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/
trying URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/3.6/ggplot2_3.2.1.zip'
Content type 'application/zip' length 3976020 bytes (3.8 MB)
downloaded 3.8 MB
package ‘ggplot2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\xiaoxiaoyi\AppData\Local\Temp\RtmpeufPQo\downloaded_packages
-
第二种:Rstudio上点击操作
image.png
2、批量安装R包:
-
1) sapply()
> pkgs <- c("tidyr","tibble","dplyr","stringr","ggplot2","ggpubr","factoextra","FactoMineR")
> sapply(pkgs, install.packages, character.only = T)
#三个参数:包含要安装的R包的名称的向量
#安装函数install.packages,character.only = T
#它只接受字符串值,它可以接受一个字符串变量
-
2)向量+循环的形式安装包
> cran_packages <- c('tidyr',
'tibble',
'dplyr',
'stringr',
'ggplot2',
'ggpubr',
'factoextra',#包含主成分分析(PCA)h函数
'FactoMineR')
> for (pkg in cran_packages){
if (! require(pkg,character.only=T) ) {
install.packages(pkg,ask = F,update = F)
require(pkg,character.only=T)
}
}#以上是向量的形式安装包
###另一种,Biocductor
> Biocductor_packages <- c('GEOquery',
'hgu133plus2.db',
"KEGG.db",
"limma",
"impute",
"GSEABase",
"GSVA",
"clusterProfiler",
"org.Hs.eg.db",
"preprocessCore",
"hugene10sttranscriptcluster.db",
"enrichplot")
> for (pkg in Biocductor_packages){
if (! require(pkg,character.only=T) ) {
BiocManager::install(pkg,ask = F,update = F)
require(pkg,character.only=T)
}
}#cran和bioconductor安装包的形式不一样
#最后,能够加载说明就已经成功。
#前面的所有提示和报错都先不要管。主要看这里
for (pkg in c(Biocductor_packages,cran_packages)){
require(pkg,character.only=T)
}#对所有的包进行加载
#没有error就是成功!
#哪个报错,就回去安装哪个。如果你没有安装xx包,却提示你xx包不存在,这也正常,是因为复杂的依赖关系,缺啥补啥。
3、下载到本地安装
1)先下载到本地,并把它放在工作目录中,或者安装时指定软件包的绝对路径。
download.file("http://bioconductor.org/packages/release/bioc/src/contrib/BiocInstaller_1.20.1.tar.gz","BiocInstaller_1.20.1.tar.gz")
install.packages("BiocInstaller_1.20.1.tar.gz", repos = NULL)
4、指定网址安装
- Cran
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
#或者
packageurl <- "http://cran.r-project.org/src/contrib/Archive/gridExtra/gridExtra_0.9.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
- bioconductor
packageurl <- "http://www.bioconductor.org/packages/2.11/bioc/src/contrib/ggbio_1.6.6.tar.gz"
#或者
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_1.0.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
二、Bioconductor安装R包:BiocManager::install()
1、 单个包安装的方法
> if (!requireNamespace("BiocManager", quietly = TRUE))#用来进行一个特定的行为,如当建议包找不到时抛出一个错误。
> install.packages("BiocManager") # 首先要安装BiocManager包
> BiocManager::install("Biobase") # 再用BiocManager安装
2、 批量安装的方法sapply()函数
bioanp <- c("pcaMethods", "GO.db", "topGO", "clusterProfiler", "biomaRt")
sapply(anp, BiocManager::install, character.only = T) # 前天你需要安装BiocManager包,方法install.packages("BiocManager")
三、Github安装R包,借助工具包devtools
>install.packages("devtools")
>library(devtools)
>install_github("RevolutionAnalytics/RHadoop")
网友评论