-
Notifications
You must be signed in to change notification settings - Fork 7
/
0. install_and_load_packages.R
109 lines (80 loc) · 3.18 KB
/
0. install_and_load_packages.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Step0 Before starting your project --------------------------------------
## Remove everything in the working environment, not including loaded libraries.
rm(list = objects( all = TRUE ))
if (!is.null( dev.list() )) dev.off()
clearhistory <- function() {
write( "", file = ".blank" )
loadhistory( ".blank" )
unlink( ".blank" )
}
clearhistory()
## basecal packages
sysPackages <- (.packages())
## data.frame(..., row.names = NULL, check.rows = FALSE,
## check.names = TRUE, fix.empty.names = TRUE,
## stringsAsFactors = default.stringsAsFactors())
options( stringsAsFactors = FALSE )
## Now winInet not supported for use in service, but the default setting of
## download.file.method is "wininet".
## If your system support "libcurl", set the downloaded method to libcurl.
if ( capabilities( "libcurl" ) == T ) {
options( download.file.method = "libcurl" )
}
options()$download.file.method
## Change the library location of the packages
## Even your updated your R, you can still use your packages.
.libPaths( c( "G:/R-packages",
"C:/Program Files/R/R-3.5.2/library") )
.libPaths()
# Step1 Setting CRAN mirror -----------------------------------------------
local({
options( repos = "https://mirrors.ustc.edu.cn/CRAN/" )
options( BioC_mirror = "https://mirrors.ustc.edu.cn/bioc/" )
})
# Step2 List of the used packages ----------------------------------------
bioPackages <-
c(
"dplyr", "stringi", "purrr", ## ERROR
"R.utils", "data.table", ## unzip and read table
"GEOquery", ## download
"FactoMineR", "factoextra", "ggfortify", ## PCA
"pheatmap", ## heatmap
"ggplot2", ## Volcano plot
"limma", "DESeq2", "edgeR", ## DEG
"clusterProfiler", "org.Hs.eg.db", ## annotation
"pathview" ## kegg
)
# Step3 Install the packages ----------------------------------------------
lapply( bioPackages,
function(bioPackage) {
if ( !require( bioPackage, character.only = T ) ) {
CRANpackages <- available.packages()
## install packages by CRAN
if ( bioPackage %in% rownames( CRANpackages ) ) {
install.packages( bioPackage )
}else{
## install packages by bioconductor
## R version >= 3.5 ===> BiocManager
if ( as.character( sessionInfo()$R.version$minor ) >= 3.5 ) {
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(bioPackage, update = TRUE, ask = FALSE)
}else{
## R version < 3.5 ===> BiocInstaller
if (!requireNamespace("BiocInstaller", quietly = TRUE))
source( "https://bioconductor.org/biocLite.R" )
BiocInstaller::biocLite( bioPackage, ask = FALSE)
}
}
}
}
)
# Step4 Remove new loaded packages ----------------------------------------
allPackages <- (.packages())
newPackages <- setdiff( allPackages, sysPackages )
lapply( newPackages,
function(package) {
package <- paste('package:', package, sep = "", collapse = NULL)
detach( package, character.only = TRUE )
}
)