R包安装的正确方式

 1 options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
 2 if(! require("devtools")) install.packages("devtools")
 3 if(! require("reshape2")) install.packages("reshape2")
 4 if(! require("ggplot2")) install.packages("ggplot2")
 5 if(! require("pheatmap")) install.packages("pheatmap")
 6 if(! require("ggfortify")) install.packages("ggfortify")
 7 if(! require("stringr")) install.packages("stringr")
 8 if(! require("survival")) install.packages("survival")
 9 if(! require("survminer")) install.packages("survminer")
10 if(! require("lars")) install.packages("lars")
11 if(! require("glmnet")) install.packages("glmnet")
12 
13 if(! require("timeROC")) install.packages("timeROC")
14 if(! require("ggpubr")) install.packages("ggpubr")
15 
16 if(! require("randomForest")) install.packages("randomForest")
17 if(! require("ROCR")) install.packages("ROCR") 
18 if(! require("Hmisc")) install.packages("Hmisc")
19 
20 if(! require("caret")) install.packages("caret")
21 # if(! require("genefilter")) install.packages("genefilter")
22 if(! require("ggstatsplot")) install.packages("ggstatsplot")
23 
24 ### 下面的包是为了临床三线表
25 if(! require("tableone")) install.packages("tableone")
26 ## 网络不好,就不要安装了。
27 ## 而且Windows电脑安装 rJava 也经常是需要人指导的。
28 # https://github.com/rstudio/rstudio/issues/2254
29 if(! require("rJava")) install.packages("rJava")
30 if(require('rJava')){
31 
32   # https://cran.r-project.org/src/contrib/Archive/ReporteRs/
33   if(! require("ReporteRs")) install.packages("ReporteRs")
34   devtools::install_github('davidgohel/ReporteRsjars')
35   devtools::install_github('davidgohel/ReporteRs')
36 }
37 
38 
39 library(devtools) 
40 source("http://bioconductor.org/biocLite.R") 
41 ## 如果你的网络实在是太差,试试看:
42 # install.packages("BiocInstaller",repos="http://bioconductor.org/packages/3.7/bioc")  
43 ## 很可惜你在中国大陆,不得不承受这个痛苦。
44 
45 options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/") 
46 library('BiocInstaller')
47 if(! require('edgeR')){
48 
49   biocLite(c('airway','DESeq2','edgeR','limma'))
50 }
51 
52 if(! require("CLL")) biocLite("CLL")
53 if(! require("org.Hs.eg.db")) biocLite('org.Hs.eg.db')
54 library(BiocInstaller)
55 options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
56 if(! require("maftools")) biocLite("maftools")
57 if(! require("RTCGA")) biocLite("RTCGA")
58 if(! require("RTCGA.clinical")) biocLite("RTCGA.clinical")
59 # https://bioconductor.org/packages/3.6/data/experiment/src/contrib/RTCGA.clinical_20151101.8.0.tar.gzn
60 if(! require("RTCGA.miRNASeq")) biocLite("RTCGA.miRNASeq")
61 if(! require("maftools")) biocLite("maftools")
62 if(! require("genefilter")) biocLite("genefilter")
63 
64 
65 # Then from : https://github.com/ShixiangWang 
66 # You don't need run the codes below, I will explain to you face to face.
67 
68 source("http://bioconductor.org/biocLite.R") 
69 packs = c("devtools", "reshape2", "ggplot2", "pheatmap", "ggfortify", "stringr", "survival",
70           "survminer", "lars", "glmnet", "timeROC", "ggpubr", "randomForest", "ROCR", "genefilter",
71           "Hmisc", "caret", "airway","DESeq2","edgeR","limma", "CLL", "org.Hs.eg.db", "maftools")
72 if(! require(pacman)) install.packages("pacman", dependencies = TRUE)
73 pacman::p_load(packs, dependencies=TRUE, character.only = TRUE)
74 # check
75 pacman::p_loaded(packs, character.only = TRUE)
76 all(pacman::p_loaded(packs, character.only = TRUE))

注:本文转自“生信技能树”

https://mp.weixin.qq.com/s?__biz=MzAxMDkxODM1Ng==&mid=2247487157&idx=1&sn=0540a2788eba7b5a96a6d4f907d92718&chksm=9b484e0eac3fc71864f0e1d5959ac5f768bd3289312c2d0776cbe663a888edd056b092175d5c&mpshare=1&scene=23&srcid=0809lYoGGKt6uOM4j8rCH40P#rd
posted @ 2018-08-09 09:31  忆昔烟雨情  阅读(7421)  评论(0编辑  收藏  举报