R包安装方法及安装记录

8 小时前 · 来自专栏 生信相关

一、安装R包的几种方法

1、直接安装

(1)对于一般的R包
install.packages("package name")
(2)对于Bioconductor的包(使用BiocManager安装)
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
BiocManager::install("package name")
注意:有时候可根据回显添加force = TRUE

2、找到R包下载地址后安装

url <- "https://cran.r-project.org/src/contrib/Archive/rvcheck/rvcheck_0.1.8.tar.gz"
install.packages(url,repos = NULL,type = "source")

3、R包下载到本地后安装

download.file("https://cran.r-project.org/src/contrib/Archive/rvcheck/rvcheck_0.1.8.tar.gz","rvcheck_0.1.8.tar.gz") 
install.packages("rvcheck_0.1.8.tar.gz",repos = NULL)

4、命令行安装

在shell的终端
sudo R CMD INSTALL package.tar.gz

在CRAN中检索R包: CRAN Packages By Name (r-project.org)

安装包就是一直失败一直装,错哪解决哪(先Google,然后必应,最后百度)……总会成功的,要是不成,当我没说。

一个很有用的网站: R Package Documentation (rdrr.io)

二、docker镜像中部分包安装时我遇到的错误及解决方法

生信途中遇上的那些坑

安装某个包,但与之相关的依赖包都安装不上时,如果没有找到解决方法,建议每个包单独安装,虽然费时且麻烦,但个人感觉安装成功的几率能大一些。

三、安装记录

以下主要是为了方便复制粘贴(不定期更新)。

1、install.packages

install.packages("stringi")
install.packages("ggplot2")
install.packages("pls")
install.packages("ggthemes")
install.packages("ggrepel")
install.packages("readxl")
install.packages("writexl")
install.packages("reshape2")
install.packages("pheatmap")
install.packages("RColorBrewer")
install.packages("remotes")
install.packages("ggpubr")
install.packages("corrplot")
install.packages("ggcorrplot")
install.packages("xml2")
install.packages("https://cran.r-project.org/src/contrib/Archive/xml2/xml2_1.3.2.tar.gz",repos = NULL,type = "source")
install.packages("nloptr")
install.packages("hrbrthemes")
install.packages("curl")
install.packages("https://cran.r-project.org/src/contrib/curl_4.3.2.tar.gz",repos = NULL,type = "source")
install.packages("httr")
install.packages("openssl") # https://github.com/openssl/openssl
install.packages("ComplexHeatmap")
install.packages("formattable")
install.packages("rstan")
install.packages("optparse")
install.packages("tidyverse")
install.packages("rvest")
install.packages("multiUS", repos="http://R-Forge.R-project.org")
install.packages("https://cran.r-project.org/src/contrib/Archive/locfit/locfit_1.5-9.4.tar.gz",repos = NULL,type = "source")
install.packages("https://cran.r-project.org/src/contrib/Archive/ArgumentCheck/ArgumentCheck_0.10.2.tar.gz",repos = NULL,type = "source")
install.packages("RCircos") # 环形图
install.packages("https://cran.r-project.org/src/contrib/Archive/rvcheck/rvcheck_0.1.8.tar.gz",repos = NULL,type = "source")
install.packages("ggalt") # 平滑折线图
install.packages ("githubinstall")
install.packages ("pacman")
install.packages("showtext") # 更改字体
install.packages("shadowtext") # 更改字体
install.packages("googleway") # 地图
install.packages("lubridate") # 日期转换
install.packages("networkD3") # 3D网络图
install.packages("IDPmisc") # https://www.rdocumentation.org/packages/IDPmisc/versions/1.1.20
install.packages("do")
install.packages("plotly") # 交互式绘图
install.packages("dygraphs")
install.packages("DT")
install.packages("echarts4r") # 版本可能存在问题
install.packages("WGCNA")
install.packages("psych") # 计算相关性
install.packages("AnnoProbe") # 用于下载GEO数据集并注释
install.packages("argparser")
install.packages("umap")
install.packages("survival")
install.packages("survminer")
install.packages("emmeans")
install.packages("factoextra") # https://github.com/kassambara/factoextra
install.packages("NMF") # 非负矩阵分解(nonnegative matrix factorization)
install.packages("chemometrics")
install.packages("compositions")
install.packages("msigdbr")
install.packages("gProfileR") # ID转换
install.packages("fdrci") # p值校正
install.packages("maxstat")
install.packages("fpc") # 计算K-means聚类推荐聚类数
install.packages("mice") # 多重插补
install.packages("ggdendro")
install.packages("svglite") # 保存图片为svg
install.packages("vegan") # cca函数
install.packages("ggpol")
install.packages("fuzzyjoin") # 忽略大小写的匹配
install.packages("pracma") # 忽略大小写的匹配

2、BiocManager::install

if (!requireNamespace("BiocManager", quietly = TRUE))
 install.packages("BiocManager")
BiocManager::install("clusterProfiler")
BiocManager::install("impute")
BiocManager::install("limma")
BiocManager::install("DEP")
BiocManager::install("SummarizedExperiment",force = TRUE)
BiocManager::install("edgeR")
BiocManager::install("DESeq2")
BiocManager::install("org.Hs.eg.db")
BiocManager::install("pathview")
BiocManager::install("AnnotationDbi")
BiocManager::install("IPO")
BiocManager::install("xcms")
BiocManager::install("KEGGREST",force = TRUE)
BiocManager::install("fmcsR")
BiocManager::install("Cairo")
BiocManager::install("ComplexHeatmap")
BiocManager::install("DLBCL")
BiocManager::install("BioNet")
BiocManager::install("RSQLite")
BiocManager::install("DirichletMultinomial",force = TRUE)
BiocManager::install("chimeraviz") # 融合基因分析结果可视化
BiocManager::install("ballgown") # 分析转录组差异表达
BiocManager::install("genefilter",force = T) # methods for filtering genes from high-throughput experiments
BiocManager::install("ChIPpeakAnno")
BiocManager::install("RMassBank")
BiocManager::install("ChIPseeker")
BiocManager::install("GSVA") # 基因集变异分析(Gene Set Variation Analysis,GSVA)
BiocManager::install("ConsensusClusterPlus") # 一致性聚类
BiocManager::install("statTarget") # 质控
BiocManager::install("cmapR") # https://bioconductor.org/packages/release/bioc/html/cmapR.html
BiocManager::install("TCGAbiolinks") # 下载TCGA数据

3、devtools::install_github

devtools::install_github("strengejacke/sjmisc")
devtools::install_github("kassambara/ggpubr")
devtools::install_github("cran/nloptr@1.2.2.3")
devtools::install_github("jokergoo/ComplexHeatmap")
devtools::install_github("https://github.com/cran/RbioRXN.git")
devtools::install_github('cytoscape/r-cytoscape.js@v0.0.7') # 提示更新相关包选项时我选择了3: None
devtools::install_github("xia-lab/OptiLCMS", build = TRUE, build_vignettes = FALSE, build_manual =TRUE)
devtools::install_github("kumine/myplot")
devtools::install_github("stan-dev/rstantools")
devtools::install_github("davidaknowles/leafcutter/leafcutter") # 可变剪切分析
devtools::install_github("alyssafrazee/RSkittleBrewer") # 颜色主题
devtools::install_github("kendomaniac/docker4seq", ref="master")
devtools::install_github("ropensci/magick")
devtools::install_github("schymane/ReSOLUTION")
devtools::install_github("dkahle/ggmap") # 绘制地图 https://github.com/dkahle/ggmap
devtools::install_github("ropensci/rnaturalearth") # 世界地图 https://github.com/ropensci/rnaturalearth
devtools::install_github("outbreak-info/R-outbreak-info") # https://github.com/outbreak-info/R-outbreak-info
devtools::install_github("ramnathv/rCharts") # 交互式绘图
devtools::install_github("yihui/recharts") # 交互式绘图
devtools::install_github("ropensci/plotly") # 交互式绘图
devtools::install_github("timelyportfolio/d3treeR")
devtools::install_github("liamgilbey/ggwaffle") # 方块图/热图
devtools::install_github("https://github.com/CDK-R/rcdklibs")
devtools::install_github("https://github.com/CDK-R/cdkr", subdir="rcdk")
devtools::install_github("seandavi/GEOquery") # https://github.com/seandavi/GEOquery
devtools::install_github("therneau/survival") # https://github.com/therneau/survival
devtools::install_github("dgrapov/CTSgetR") # https://github.com/dgrapov/CTSgetR 化合物ID转换
devtools::install_github("adam-sam-brown/ksRepo") # https://github.com/adam-sam-brown/ksRepo
devtools::install_github("cBioPortal/cgdsr") # https://github.com/cBioPortal/cgdsr/blob/master/README.md
devtools::install_github("Bioconductor/GenomicDataCommons")
devtools::install_github("javadnoorb/pathview")

4、 remotes::install_github

remotes::install_github("YuLab-SMU/ggtree") 
remotes::install_github("SVA-SE/kilde")  # sample_data函数
remotes::install_github("SymbolixAU/googlePolylines")
remotes::install_github("SymbolixAU/googleway")
remotes::install_github("rvlenth/emmeans", dependencies = TRUE, build_opts = "") # https://github.com/rvlenth/emmeans
remotes::install_github("YuLab-SMU/createKEGGdb")

5、MetaboAnalystR

Step 1. Install package dependencies

================== Option 1 ==================
Enter the R function (metanr_packages) and then use the function. A printed message will appear informing you whether or not any R packages were installed.
metanr_packages <- function(){
metr_pkgs <- c("impute", "pcaMethods", "globaltest", "GlobalAncova", "Rgraphviz", "preprocessCore", "genefilter", "SSPA", "sva", "limma", "KEGGgraph", "siggenes","BiocParallel", "MSnbase", "multtest", "RBGL", "edgeR", "fgsea", "devtools", "crmn")
list_installed <- installed.packages()
new_pkgs <- subset(metr_pkgs, !(metr_pkgs %in% list_installed[, "Package"]))
if(length(new_pkgs)!=0){if (!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
        BiocManager::install(new_pkgs)
        print(c(new_pkgs, " packages added..."))
if((length(new_pkgs)<1)){
        print("No new packages added...")
metanr_packages()
================== Option 2 ==================
Use the pacman R package (for those with >R 3.5.1).
install.packages("pacman")
library(pacman)
pacman::p_load(c("impute", "pcaMethods", "globaltest", "GlobalAncova", "Rgraphviz", "preprocessCore", "genefilter", "SSPA", "sva", "limma", "KEGGgraph", "siggenes","BiocParallel", "MSnbase", "multtest", "RBGL", "edgeR", "fgsea"))

Step 2. Install the package

================== Option A) Install the package directly from github using the devtools package.==================
# Step 1: Install devtools
install.packages("devtools")
library(devtools)
# Step 2: Install MetaboAnalystR without documentation
devtools::install_github("xia-lab/MetaboAnalystR", build = TRUE, build_vignettes = FALSE)
# Step 2: Install MetaboAnalystR with documentation
devtools::install_github("xia-lab/MetaboAnalystR", build = TRUE, build_vignettes = TRUE, build_manual =T)
================== Option B) Install from a pre-built source package ==================