安裝包及設(shè)置鏡像
安裝包
安裝CRAN軟件
install.packages(pkgs, lib, repos = getOption("repos"), quiet = FALSE)
lib: character vector giving the library directories where to install the packages. Recycled as needed. If missing, defaults to the first element of .libPaths().
repos: character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as "https://cloud.r-project.org". For more details on supported URL schemes see url.
quiet: logical: if true, reduce the amount of output.
安裝Bioconductor 相關(guān)包
# Source biocLite from web
source("https://bioconductor.org/biocLite.R")
biocLite("package_name")
# Use biocLite under BiocInstaller
install.packages("BiocInstaller")
BiocInstaller::biocLite("package_name")
biocLite(pkgs=c("Biobase", "IRanges", "AnnotationDbi"),
suppressUpdates=FALSE,
suppressAutoUpdate=FALSE,
siteRepos=character(),
ask=TRUE, ...)
Install or update Bioconductor, CRAN, or GitHub packages
if (!requireNamespace("BiocManager", quietly=TRUE))
install.packages("BiocManager")
BiocManager::install("package_name")
Note:
BioInstallerandbiocLiteare deprecated use thebiocmanagercran package instead.
本地安裝源碼包
install.packages("path/to/pkg/package_name.tar.gz", repos = NULL, type = "source")
源碼編譯安裝的時(shí)候,要將源碼壓縮成tar.gz格式再安裝,zip格式會(huì)出奇怪的錯(cuò)誤。
R包相關(guān)操作
# 查看R包安裝位置
.libPaths()
# 查看已安裝的包
installed.packages()
# 查看包版本
packageVersion("package_name")
# 更新包
update.packages("package_name")
# 加載包
library("package_name")
require("package_name")
# 查看加載的包
.packages()
# 移除已加載的包(將包從R運(yùn)行環(huán)境中移除)
detach("package_name")
# 徹底刪除已安裝的包:
remove.packages("package_name", lib = file.path("path/to/library"))
鏡像設(shè)置
常用鏡像地址
| Name | URL | host | type |
|---|---|---|---|
| China (Anhui) [https] | https://mirrors.ustc.edu.cn/bioc/ | 中科大 | CRAN_mirror |
| China (Anhui) | http://mirrors.ustc.edu.cn/bioc/ | 中科大 | CRAN_mirror |
| China (Beijing) [https] | https://mirrors.tuna.tsinghua.edu.cn/CRAN/ | 清華 | BioC_mirror |
| China (Beijing) | http://mirrors.tuna.tsinghua.edu.cn/CRAN/ | 清華 | BioC_mirror |
CRAN鏡像下載安裝包
# 從CRAN鏡像下載安裝包
install.packages(pkgs, repos = "https://mirrors.ustc.edu.cn/CRAN/")
# 從BioC鏡像安裝包
biocLite(pkg, siteRepos = "http://mirrors.ustc.edu.cn/bioc/")
常用函數(shù)
# 查看當(dāng)前鏡像地址
getOption("repos")
# 查看R_HOME地址
R.home()
R_HOME/doc/CRAN_mirrors.csv
R_HOME/doc/BioC_mirrors.csv
將鏡像添加到配置文件
Bioconductor 鏡像源配置文件之一是 .Rprofile (linux 下位于 ~/.Rprofile )。
在文末添加如下語(yǔ)句:
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")