R包安装的4种方式#
1.从CRAN安装
install.packages("包名")
# 或直接进行指定
install.packages("https://cran.r-project.org/src/contrib/pak_0.9.0.tar.gz", repos=NULL, type="source")
# CRAN查询网站:https://search.r-project.org/
由于该网站在国外,国内连接容易网络不稳定,因此可以选择国内镜像。
数信云自建CRAN镜像使用:数信院CRAN镜像源使用
2.从Bioconductor安装
# 先下载BiocManager
install.packages(“BiocManager”)
# 然后使用BiocManager从Biocondautor库下载数据
BiocManager::install("包名")
# Biocondautor查询网站:https://bioconductor.org/
数信云自建bioconductor镜像使用:数信院bioconductor镜像源使用
3.从Github安装
# 方法一:
# 使用install.packages指定github链接进行下载
install.packages("https://github.com/r-lib/devtools", repos=NULL, type="source")
# 方法二:
# 使用remotes包进行下载
install.packages("remotes")
remotes::install_github("sqjin/CellChat")
# 使用镜像加速
remotes::install_github("sqjin/CellChat",host = "https://kgithub.com/")
# 方法三:
# 使用devtools包进行下载,使用方式与remotes相同
install.packages("devtools")
devtools::install_github("sqjin/CellChat")
# 使用镜像加速
devtools::install_github("sqjin/CellChat",host = "https://kgithub.com/")
4.从本地安装包
有些github的R包安装总是遇到下载错误的问题,一般都是因为github连接不稳定导致的。
为了解决这个问题,可以先在个人电脑使用梯子将对应github包下载到本地,并上传到服务器进行本地安装。
# 方法一:
install.packages("devtools")
devtools::install_local(path = "/path/to/package.tar.gz", dependencies = TRUE)
devtools::install_local(path = "/path/to/package.zip", dependencies = TRUE)
# 方法二:
install.packages("remotes")
remotes::install_local(path = "/path/to/package.tar.gz", dependencies = TRUE)
remotes::install_local(path = "/path/to/package.zip", dependencies = TRUE)
还有一些R包是tar.gz或zip结尾的文件,可以使用下面的方法进行安装
install.packages("/path/to/package.tar.gz", repos = NULL, type = "source")
install.packages("/path/to/package.zip", repos = NULL, type = "source")