forked from rafalab/dsbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-libraries.Rmd
165 lines (115 loc) · 4.24 KB
/
install-libraries.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
159
160
161
162
---
title: "Installation of Data Science"
author: Emmanuel-R8
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE, eval = TRUE)
```
# Intro
Following are installation steps to locally 'compile' this bookdown. The instructions are targeted for linux users. Instructions will be added for Windows and Mac users at a later stage.
Each installation of R and RStudio are different, so it is likely that those steps will fail for some of them.
# Installation of the required packages
## Environment
R and RStudio are expected to be installed. An internet connection is required ;-).
OPTIONAL: To render this installation file, the `rmarkdown` package is required, but the instructions can be read on a normal text editor.
On a linux system, some packages/tools are required:
- Normal development environment, e.g. what the `build-essential` package provides on Debian/Ubuntu.
- curl, git, [...]
- development headers for libpoppler-cpp-dev
Make sure that the current working directory is the top of the tree, that is, just under `dsbook`.
```{r}
# This is a small utility function to avoid re-installing packages
install_pkg <- function(name, ...) {
if (!requireNamespace(name, quietly = TRUE)){
install.packages(name, ...)
}
}
```
Now that `packrat` is installed and initialised, `devtools` can be re-installed within the `packrat` environment.
The instructions list only a few packages, but they will in turn pull many others. During installation, a number of packages will require some development headers from your Linux distribution.
## Installation of the relevant packages
The tidyverse packages is the central platform the book builds on.
```{r}
install_pkg("tidyverse")
install_pkg("tidytext")
```
Machine learning packages:
```{r}
install_pkg("caret")
install_pkg("lpSolve")
install_pkg("randomForest")
install_pkg("gam")
```
Additional visualisation packages and `ggplot2` addins:
```{r}
install_pkg("scatterplot3d")
install_pkg("VennDiagram")
install_pkg("maps")
install_pkg("mapproj")
install_pkg("animation")
install_pkg("gridExtra")
install_pkg("ggthemes")
install_pkg("ggrepel")
install_pkg("ggridges")
install_pkg("gganimate")
devtools::install_github("rensa/ggflags")
```
Some various utilities:
```{r}
install_pkg("devtools")
install_pkg("kableExtra")
install_pkg("matrixStats")
install_pkg("gtools")
install_pkg("pdftools")
install_pkg("english")
```
Now the `dslab` package that provides the information and scripts presented in the book can be downloaded.
```{r}
install_pkg("dslabs")
install_pkg("rafalib")
```
A package from the BioConductor repository:
```{r}
install_pkg("BiocManager")
BiocManager::install("genefilter")
```
A number of datasets are used throughout the book.
```{r}
install_pkg("gutenbergr")
install_pkg("Lahman")
install_pkg("countrycode")
install_pkg("NHANES")
install_pkg("HistData")
install_pkg("textdata")
```
Finally, the `tidytext` text mining package requires external dictionaries for sentiment analysis. Those require agreeing to licenses.
```{r}
tidytext::get_sentiments(lexicon = "afinn")
tidytext::get_sentiments(lexicon = "bing")
tidytext::get_sentiments(lexicon = "nrc")
```
## Book creation packages
`bookdown` generates the final output. `tufte` provides a style that Edward Tufte uses in his books and handouts. It is not the default style.
```{r}
install_pkg("bookdown")
install_pkg("tufte")
```
# Book generation
**The whole generation process is sometimes hit and miss. Re-running the generation commands sometimes solves prolems.**
The following is to generate a pdf version. The format can be customised by changing options at the top of the `index.Rmd` file.
```{r}
bookdown::render_book("index.Rmd", output_format = "bookdown::pdf_book")
```
If the first build succeeds, you could in principle to speed up the next generation, add `clean_envir = FALSE` to the options passed to `render_book`.
Likewise, this generates a Gitbook...
```{r}
bookdown::render_book("index.Rmd", output_format = "bookdown::gitbook", clean_envir=FALSE)
```
... or an e-book.
```{r}
bookdown::render_book("index.Rmd", output_format = "bookdown::epub_book", clean_envir=FALSE)
```
```{r}
# Not working yet
# bookdown::render_book("index.Rmd", output_format="tufte::tufte_book", clean_envir=FALSE)
```