-
Notifications
You must be signed in to change notification settings - Fork 12
/
0-install.Rmd
158 lines (123 loc) · 5.9 KB
/
0-install.Rmd
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
title: "0. Setup"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
This file will walk through the installation of any needed packages. We will consider three types of packages:
* **CRAN** - this is where most R packages reside, and it has extensive automated testing to ensure quality.
* **GitHub** - these are more "bleeding edge" packages that may not have as much testing.
* **BioConductor** - these are packages designed for computational biology applications.
General notes
* If given the choice, do not compile packages from source (it's more error-prone).
* If there's a corruption error message, try restarting your R session and trying again (Session -> Restart R).
* If asked, try to update existing packages. But if that causes errors, run it again and don't update existing packages.
## Check requirements
```{r check_requirements}
min_r_version = 3.6
r_version = as.numeric(paste0(R.version["major"], ".", as.integer(R.version["minor"])))
if (r_version < min_r_version) {
cat(paste0("Error: your R software is out of date.\n",
"Minimum version required: ", min_r_version, "\n",
"R version detected: ", r_version, "\n",
"Please download and install the latest version from: https://cloud.r-project.org/"))
} else {
cat("Your R software is up to date:", r_version)
}
```
## Package installation
### Cran packages
```{r cran_packages}
packages = list(
cran = c("h2o", # glrm, anomaly forests
"dbscan", # hdbscan
"poLCA", # latent class analysis
"umap", # umap
"BiocManager", # needed to install hopach
"rio", # import / export
"dplyr", # data manipulation
"ggplot2", # plotting
"remotes") # installation of packages from GitHub
)
# Try to load each package and save the result.
(install_status = suppressWarnings(sapply(packages$cran, require, character.only = TRUE, quietly = TRUE)))
# Check if any packages still need to be installed, and if so, try to install them.
if (sum(!install_status) > 0) {
cat("The following CRAN packages need to be installed:",
paste0(paste(names(install_status)[!install_status], collapse = ", "), ".\n"))
# Install any needed packages.
install.packages(packages$cran[!install_status],
# Specify repository so that we can install when knitting this file.
repos = "http://cran.rstudio.com")
# Load the newly installed packages.
recheck = suppressWarnings(sapply(packages$cran[!install_status], require, character.only = TRUE, quietly = TRUE))
if (sum(!recheck) > 0) {
cat("Failed to install the following CRAN packages:",
paste0(paste(names(recheck)[!recheck], collapse = ", "), "."),
"\nPlease try installing them manually with install.packages()",
"and closely reviewing any error messages.\n")
} else {
cat("CRAN packages installed successfully.\n")
}
} else {
cat("All CRAN packages are installed and loaded.\n")
}
```
### GitHub packages
Note that the ck37r package is now also on CRAN, but it's good to show GitHub installation for posterity.
```{r github_packages}
packages$github = c("ck37r" = "ck37/ck37r")
# Try to load each package and save the result.
install_status = suppressWarnings(sapply(names(packages$github),
require, character.only = TRUE, quietly = TRUE))
# Check if any packages still need to be installed, and if so, try to install them.
if (sum(!install_status) > 0) {
cat("The following GitHub packages need to be installed:",
paste0(paste(names(install_status)[!install_status], collapse = ", "), "."))
# Install any needed packages.
remotes::install_github(packages$github[!install_status])
# Load the newly installed packages.
recheck = suppressWarnings(sapply(names(packages$github)[!install_status],
require, character.only = TRUE, quietly = TRUE))
if (sum(!recheck) > 0) {
cat("Failed to install the following GitHub packages:",
paste0(paste(packages$github[names(recheck)[!recheck]], collapse = ", "), "."),
"\nPlease try installing them manually with remotes::install_github()",
"and closely reviewing any error messages.\n")
} else {
cat("GitHub packages installed successfully.\n")
}
} else {
cat("All GitHub packages are installed and loaded.\n")
}
```
### Bioconductor packages
```{r biocon_packages}
packages$bioconductor = c("hopach")
# Try to load each package and save the result.
(install_status = suppressWarnings(sapply(packages$bioconductor,
require, character.only = TRUE, quietly = TRUE)))
# Check if any packages still need to be installed, and if so, try to install them.
if (sum(!install_status) > 0) {
cat("The following Bioconductor packages need to be installed:",
paste0(paste(names(install_status)[!install_status], collapse = ", "), "."))
# Install any needed packages.
BiocManager::install(packages$bioconductor[!install_status])
# Load the newly installed packages.
recheck = suppressWarnings(sapply(packages$bioconductor[!install_status],
require, character.only = TRUE, quietly = TRUE))
if (sum(!recheck) > 0) {
cat("Failed to install the following Bioconductor packages:",
paste0(paste(packages$github[names(recheck)[!recheck]], collapse = ", "), "."),
"\nPlease try installing them manually with BiocManager::install()",
"and closely reviewing any error messages.\n")
} else {
cat("Bioconductor packages installed successfully.\n")
}
} else {
cat("All Bioconductor packages are installed and loaded.\n")
}
```
## Slides
Now open up the slides available here: [https://dlab-berkeley.github.io/Unsupervised-Learning-in-R/slides.html](https://dlab-berkeley.github.io/Unsupervised-Learning-in-R/slides.html)