美文网首页
Linux | 安装 R

Linux | 安装 R

作者: iBioinformatics | 来源:发表于2023-03-24 09:50 被阅读0次

    1. 查看环境

    conda info --envs
    

    2. 创建新的环境R3.6

    conda create -n R3.6
    

    3. 激活该环境

    首次使用 source activate 命令激活虚拟环境 R3.6

    source activate R3.6
    # 退出虚拟环境
    conda deactivate
    

    否则会报下面的错

    以后使用 conda activate 命令激活虚拟环境
    conda activate R3.6

    4. 在conda中找 r

    conda search r
    

    5. 下载

    conda install r -base
    
    #### 安装RStudio
    conda install rstudio
    

    6. 调用

    R 按 enter

    调用rstudio

    然后就通过xmanager打开了

    7. 安装R包

    1、直接安装

    (1)对于一般的R包

    install.packages("package name")
    

    (2)对于Bioconductor的包(使用BiocManager安装)先装BiocManager,再安装所需R包即可。

    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
    

    也可指定安装库路径:

    R CMD INSTALL /.../mypackage.tar.gz --library=/your/lib/path
    

    更多参数--help一下

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

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

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

    如果不指定R包安装的路径,R包会安装在/your/R/lib64/R/library中,这也是R自带的基础包的目录。

    安装记录

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

    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")
    

    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") # 一致性聚类
    

    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
    

    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
    

    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 ==================
    install.packages("https://www.dropbox.com/s/pp9vziji96k5z5k/MetaboAnalystR_3.2.0.tar.gz", repos = NULL, method = "wget")
    
    ================== Option C) Clone Github and install locally ==================
    git clone https://github.com/xia-lab/MetaboAnalystR.git
    R CMD build MetaboAnalystR
    R CMD INSTALL MetaboAnalystR_3.2.0.tar.gz
    

    参考链接:
    https://www.jianshu.com/p/78c710301d2e

    相关文章

      网友评论

          本文标题:Linux | 安装 R

          本文链接:https://www.haomeiwen.com/subject/iwiirdtx.html