-
Notifications
You must be signed in to change notification settings - Fork 1
/
03-install_packages.Rmd
505 lines (317 loc) · 22 KB
/
03-install_packages.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# Install Packages
```{r, include=FALSE, comment=FALSE}
library(tidyverse, quietly = TRUE)
library(kableExtra)
```
![](images/packages.png)
Learn what packages are and how to get them.
-----------
## Package FAQ
### What are packages ?
> $R$ packages are collections of functions and data sets (just files) developed by the community (or you). They increase the power of $R$ by improving existing base $R$ functionalities, or by adding new ones.
When you download $R$ you are only getting the bare-bones, most basic files. This is nice, as it keeps the program from hogging your entire hard drive, but doesn't offer much in terms of data anaysis. Today there are over 10,000 packages available on $CRAN$ alone, so downloading all of them would be silly and probably fill your computer several times over. Individual users are left with the freedom to choose which packages they need.
```{block, type="rmdlink"}
More information may be found here: https://www.datacamp.com/community/tutorials/r-packages-guide
```
### Where can you get packages ?
A repository is a place where packages are located so you can install them from it. Typically they are online and accesible to everyone. Three of the most popular repositories for $R$ packages are:
```{r, echo=FALSE}
tribble( ~image_logo, ~description,
"![](images/cran_logo.png)",
"**[$CRAN$:](https://cran.r-project.org/)** the official repository, it is a network of $ftp$ and web servers mantained by the $R$ community around the world. It is coordinated by the $R$ foundation, and for a package to be published here it needs to pass several tests [here](https://cran.r-project.org/web/packages/policies.html).",
"![](images/GitHub_logo.png)",
"**[$GitHub$:](https://github.com/)** although this is not $R$ specific, $GitHub$ is probably the most popular repository for open source projects. Its popularity comes from the unlimited space for open source, the integration with $git$, a version control software, and its ease to share and collaborate with others. But be aware that there is no review process associated to it. (All the files for this eBook are stored on $GitHub$.)",
"![](images/bioconductor_logo.png)",
"**[Bioconductor:](https://www.bioconductor.org/)** this is a topic specific repository, intended for open source software for bioinformatics. As $CRAN$, it has its own [submission and review processes](https://www.bioconductor.org/developers/package-submission/), and its community is very active having several conferences and meetings per year.") %>%
kableExtra::kable(col.names = c("", "Repository"),
align = "l")
```
## Installing packages
Installing is the act of getting the package files onto your computer and stored in a location on your hard drive where $R$ can find them. Usually the files are zipped/compress and must be extracted/unpacked. The directions below will walk you through the automated process of using the user interface in $R Studio$ *(rather than actual syntax)*.
In **R Studio**:
1. Click on the **Packages** tab in the panel with the most tabs
2. Click on the word **Install** just under and to the left of the tab
3. In the box labelled **"Packages"**, type the name of the package you would like to download. You can do several at once, just seperate them with at least one space or a comma.
```{block type='rmdlightbulb', echo=TRUE}
**You only need to INSTALL packages ONCE per computer.**
Leave the installation *"library path"* as the default. Also, make sure the box for *"Installing dependencies"* box is checked.
```
![](images/Install_Package_Screenshot.png){width=600px}
? You can *copy-and-paste* the following list into the box (labeled 3 above) to load the packages that we find most commonly used. You can install more packages at any time.
```{block type='rmdimportant', echo=TRUE}
**Useful Package List**
tidyverse, furniture, pander, stargazer, texreg, xtable, kableExtra, RColorBrewer, gghighlight, ggthemes, ggfortify, ggalt, ggExtra, GGally, ggeffects, corrplot, gpairs, gridextra, likert, vcd, scales, cowplot, yarrr, psych, polycor, corpcor, sjlabelled, sjPlot, sjmisc, sjstats, Hmisc, labelled, afex, emmeans, corpcor, multicomp, multcompView, car, effects, predictmean, nlme, lme4, lmerTest, HLMdiag, geepack, gee, gee4, optimx, MuMIn, lavaan, OpenMx, sem, semPlot, randomForest, randomForestSRC, ggRandomForests, party, partykit, mgcv, glmnet, survival, caret, bookdown, blogdown, tidytex, xaringan, REDCapR, redcapAPI, devtools, testthat, roxygen2, eRm, ltm, lsr, heplots, magrittr, hexbin, leaps, mlmRev, MuMIn, ISwR, VIM, effects, usethis, tinytex
```
When you click the **Install** buttom, a smaller window *may* asks if you would like to "re-start $R$ prior to installing", choose "no" and manually close and open the $R Studio$ program once all packages have been downloaded, unpacked, and checked *(saves time)*. This may take a few minutes, especially if you have selected multiple packages.
## Useful Packages on CRAN
```{block type='rmdlink', echo=TRUE}
A curated list of handy $R$ packages and tools can be found at [awesome-r.com](https://awesome-r.com/)
```
### The Tidy-Universe, a META package from $R Studio$
> The [`tidyverse`](https://www.tidyverse.org/) is an opinionated **collection of $R$ packages** designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
The **core tidyverse** includes the packages that you are likely to use in everyday data analyses. As of `tidyverse 1.2.0`, the top 8 packages in the following table are included in the core tidyverse.
The tidyverse also includes many other packages with more specialised usage. They are not loaded automatically with `library(tidyverse)`, so you'll need to load each one with its own call to `library()`.
| website | description |
|----------:|:------------|
| [`dplyr`](https://dplyr.tidyverse.org/) | A Grammar of Data Manipulation |
| [`forcats`](https://forcats.tidyverse.org/) | Tools for Working with Categorical Variables *(Factors)* |
| [`ggplot2`](https://ggplot2.tidyverse.org/) | Create Elegant Data Visualisations Using the Grammar of Graphics |
| [`purrr`](https://purrr.tidyverse.org/) | Functional Programming Tools |
| [`readr`](https://readr.tidyverse.org/) | Read Rectangular Text Data |
| [`stringr`](https://stringr.tidyverse.org/) | Simple, Consistent Wrappers for Common String Operations *(Text)* |
| [`tibble`](https://tibble.tidyverse.org/) | Simple Data Frames |
| [`tidyr`](https://tidyr.tidyverse.org/) | Easily Tidy Data with
| [`broom`](https://github.com/tidymodels/broom) | Convert Statistical Analysis Objects into Tidy Tibbles
| [`haven`](https://haven.tidyverse.org/) | Import and Export **SPSS**, **Stata** and **SAS** Files
| [`hms`](https://github.com/tidyverse/hms) | Pretty Time of Day
| [`lubridate`](https://lubridate.tidyverse.org/) | Make Dealing with Dates a Little Easier
| [`magrittr`](https://magrittr.tidyverse.org/) | A Forward-Pipe Operator for **$R$**
| [`glue`](https://github.com/tidyverse/glue) | Interpreted String Literals |
| [`readxl`](https://readxl.tidyverse.org/) | Read **Excel** Files
| [`tibble`](https://tibble.tidyverse.org/) | Simple Data Frames
-------------------------------------
### Groups of Individual Packages on $CRAN$ {.tabset}
#### TinyTex
TinyTeX is a custom LaTeX distribution based on TeX Live that is small in size, but functions well in most cases, especially for R users. If you run into the problem of missing LaTeX packages, it should be super clear to you what you need to do (in fact, R users won’t need to do anything). You only install LaTeX packages you actually need.
| website | description |
|----------:|:------------|
| [`tinytex`](https://yihui.org/tinytex/) | custom LaTeX distribution based on TeX Live |
#### Creating Tables
```{r, include=FALSE}
package_list_tables <- c("furniture",
"pander",
"stargazer",
"texreg",
"xtable",
"kableExtra")
```
| website | description |
|------------:|:------------|
| [`furniture`](http://tysonbarrett.com/furniture/) | Tables for Quantitative Scientists |
| [`pander`](https://rapporter.github.io/pander/) | An R 'Pandoc' Writer (makes tables look nice) |
| [`stargazer`](https://www.jakeruss.com/cheatsheets/stargazer/) | Well-Formatted Regression and Summary Statistics Tables |
| [`texreg`](https://diffuseprior.wordpress.com/2013/01/20/texreg-a-package-for-beautiful-and-easily-customizable-latex-regression-tables-from-r/) | Conversion of R Regression Output to LaTeX or HTML Tables |
| [`xtable`](https://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf) | Export Tables to LaTeX or HTML |
| [`kableExtra`](https://haozhu233.github.io/kableExtra/awesome_table_in_html.html#overview) | Construct Complex Table with `kable` and Pipe Syntax |
#### Visualization
```{r, include=FALSE}
package_list_visual <- c("RColorBrewer",
"gghighlight",
"ggthemes",
"ggfortify",
"ggalt",
"ggExtra",
"GGally",
"ggeffects",
"corrplot",
"gpairs",
"gridextra",
"likert",
"vcd",
"scales",
"cowplot",
"yarrr")
```
| website | description |
|------------:|:------------|
| [`RColorBrewer`](https://data.library.virginia.edu/setting-up-color-palettes-in-r/) | Color Palettes |
| [`gghighlight`](https://github.com/yutannihilation/gghighlight) | Highlight Lines and Points in `ggplot2` |
| [`ggthemes`](https://www.ggplot2-exts.org/ggthemes.html) | Extra Themes, Scales, and Geoms for `ggplot2` |
| [`ggExtra`](https://www.ggplot2-exts.org/ggExtra.html) | Add Marginal Histograms to `ggplot2`, and More `ggplot2` Enhancements |
| [`ggfortify`](https://github.com/sinhrks/ggfortify) | Data Visualization Tools for Statistical Analysis Results |
| [`ggalt`](https://github.com/hrbrmstr/ggalt) | Lots of extras for `ggplot2` |
| [`GGally`](https://ggobi.github.io/ggally/#canonical_correlation_analysis) | Extension to `ggplot2` |
| [`corrplot`](https://rstudio-pubs-static.s3.amazonaws.com/240657_5157ff98e8204c358b2118fa69162e18.html) | Visualization of a Correlation Matrix |
| `gpairs` | The Generalized Pairs Plot |
| [`gridextra`](https://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html) | Miscellaneous Functions for "Grid" Graphics |
| [`likert`](https://github.com/jbryer/likert) | Analysis and Visualization Likert Items |
| [`vcd`](http://www.datavis.ca/courses/VCD/vcd-tutorial.pdf) | Visualizing Categorical Data |
| [`scales`](https://github.com/r-lib/scales) | Scale Functions for Visualization |
| [`cowplot`](https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html) | Streamlined Plot Theme & Annotations for `ggplot2` |
| [`yarrr`](https://ndphillips.github.io/piratesguide.html) | The Pirate's Guide to $R$ |
#### Generally Handy
```{r, include=FALSE}
package_list_general <- c("psych",
"polycor",
"corpcor",
"sjlabelled",
"sjPlot",
"sjmisc",
"sjstats",
"Hmisc",
"labelled")
```
| website | description |
|------------:|:------------|
| `polycor` | Polychoric and Polyserial Correlations |
| [`psych`](http://personality-project.org/r/psych/) | Psychological or Psychometric Procedures |
| [`corpcor`](http://strimmerlab.org/software/corpcor/) | Covariance and (Partial) Correlation |
| [`sjlabelled`](https://strengejacke.github.io/sjlabelled/) | Labelled Data Utility Functions |
| [`sjPlot`](http://www.strengejacke.de/sjPlot/) | Data Visualization for Statistics in Social Science |
| [`sjmisc`](http://www.strengejacke.de/sjmisc/) | Data and Variable Transformation Functions |
| [`sjstats`](http://www.strengejacke.de/sjstats/) | Convenient Functions for Common Statistical Computations |
| [`Hmisc`](http://biostat.mc.vanderbilt.edu/wiki/Main/Hmisc) | Harrell Miscellaneous |
| [`labelled`](https://github.com/larmarange/labelled) | Manipulating Labelled Data |
#### t-Tests, ANOVA, and RM ANOVA
```{r, include=FALSE}
package_list_anova <- c("afex",
"emmeans",
"corpcor",
"multicomp",
"multcompView",
"VIM")
```
| website | description |
|------------:|:------------|
| [`afex`](https://github.com/singmann/afex) | Analysis of Factorial Experiments |
| [`emmeans`](https://github.com/rvlenth/emmeans) | Estimated Marginal Means, aka Least-Squares Means |
| [`multicomp`](http://multcomp.r-forge.r-project.org/) | Simultaneous Inference in General Parametric Models |
| `multcompView` | Visualizations of Paired Comparisons |
| [`VIM`](https://www.datacamp.com/community/tutorials/visualize-data-vim-package) | Visualization and Imputation of Missing Values |
#### Regression (ML, GLM)
```{r, include=FALSE}
package_list_regression <- c("car",
"effects",
"predictmeans",
"effects")
```
| website | description |
|------------:|:------------|
| [`car`](https://www.statmethods.net/stats/rdiagnostics.html) | Companion to Applied Regression |
| [`effects`](https://www.jstatsoft.org/article/view/v008i15/effect-displays-revised.pdf) | Effect Displays for Linear, Generalized Linear, and Other Models |
| `predictmeans` | Calculate Predicted Means for Linear Models |
|`effects` | Effect Displays for Linear, Generalized Linear, and Other Models |
#### Multilevel Models (MLM, HLM, GEE)
```{r, include=FALSE}
package_list_multilevel <- c("nlme",
"lme4",
"lmerTest",
"HLMdiag",
"geepack",
"gee",
"gee4",
"optimx",
"MuMIn")
```
| website | description |
|------------:|:------------|
| [`nlme`](http://davidakenny.net/papers/k&h/MLM_R.pdf) | Linear and Nonlinear Mixed Effects Models |
| [`lme4`](https://github.com/lme4/lme4/) | Linear Mixed-Effects Models |
| [`lmerTest`](https://github.com/runehaubo/lmerTestR) | Tests in Linear Mixed Effects Models |
| [`HLMdiag`](https://github.com/aloy/HLMdiag) | Diagnostic Tools for Hierarchical (Multilevel) Linear Models |
| [`geepack`](https://cran.r-project.org/web/packages/geepack/vignettes/geepack-manual.pdf) | Generalized Estimating Equation Package |
| [`gee`](https://cran.r-project.org/web/packages/gee/gee.pdf) | Generalized Estimation Equation Solver |
| [`gee4`](https://github.com/ypan1988/gee4) | Generalised Estimating Equations (GEE/WGEE) |
| [`optimx`](file:///C:/Users/A00315273/Downloads/v43i09.pdf) | A Replacement and Extension of the `optim()` Function |
| [`MuMIn`](https://sites.google.com/site/rforfishandwildlifegrads/home/mumin_usage_examples) | Multi-Model Inference |
#### Structural Equation Modeling (SEM)
```{r, include=FALSE}
package_list_sem <- c("lavaan",
"OpenMx",
"sem",
"semPlot")
```
| website | description |
|------------:|:------------|
| [`lavaan`](http://lavaan.org) | Latent Variable Analysis |
| [`OpenMx`](https://openmx.ssri.psu.edu/) | Extended Structural Equation Modelling |
| [`sem`](https://www.methodsconsultants.com/tutorial/structural-equation-models-using-the-sem-package-in-r/) | Structural Equation Modelling |
| [`semPlot`](http://sachaepskamp.com/semPlot/examples) | Path Diagrams and Visual Analysis of Various SEM Packages' Output |
#### Random Forests
```{r, include=FALSE}
package_list_forest <- c("randomForest",
"randomForestSRC",
"ggRandomForests",
"party",
"partykit")
```
| website | description |
|------------:|:------------|
| [`randomForest`](https://www.guru99.com/r-random-forest-tutorial.html) | Random Forests for Classification and Regression |
| [`randomForestSRC`](http://www.riptutorial.com/r/example/13086/random-forest-survival-analysis-with-randomforestsrc) | for Survival, Regression, and Classification |
| [`ggRandomForests`](https://arxiv.org/pdf/1612.08974.pdf) | Visually Exploring Random Forests |
| [`party`](http://party.r-forge.r-project.org/) | A Laboratory for Recursive Partytioning |
| [`partykit`]() | A Toolkit for Recursive Partytioning |
#### Other Models
```{r, include=FALSE}
package_list_models <- c("mgcv",
"glmnet",
"survival",
"caret")
```
| website | description |
|------------:|:------------|
| [`mgcv`](https://people.maths.bris.ac.uk/~sw15190/mgcv/tampere/mgcv.pdf) | Mixed GAM Computation Vehicle with Automatic Smoothness Estimation |
| [`glmnet`](https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html) | Lasso and Elastic-Net Regularized Generalized Linear Models|
| [`survival`](https://github.com/therneau/survival) | Survival Analysis |
| [`caret`](https://topepo.github.io/caret/index.html) | Classification and Regression Training |
#### Reproducibility and Reporting
```{r, include=FALSE}
package_list_report <- c("bookdown",
"blogdown",
"xaringan")
```
| website | description |
|------------:|:------------|
| [`bookdown`](https://bookdown.org/) | Authoring Books and Technical Documents |
| [`blogdown`](https://bookdown.org/yihui/blogdown/) | Create Blogs and Websites|
| [`xaringan`](https://github.com/yihui/xaringan) | Presentation Ninja |
*Note: `slidify` & `ReportRs` have been removed from $CRAN$*
#### REDCap Interface
```{r, include=FALSE}
package_list_redcap <- c("REDCapR",
"redcapAPI")
```
| website | description |
|------------:|:------------|
| [`redcapAPI`](https://github.com/nutterb/redcapAPI/wiki) | Interface to $REDCap$ |
| [`REDCapR`](https://github.com/OuhscBbmc/REDCapR) | Interaction Between $R$ and $REDCap$ |
#### Creating Your Own Packages
```{r, include=FALSE}
package_list_package <- c("devtools",
"testthat",
"roxygen2")
```
| website | description |
|------------:|:------------|
| [`devtools`](https://github.com/r-lib/devtools) | Tools to Make Developing $R$ Packages Easier|
| [`testthat`](https://github.com/r-lib/testthat) | Unit Testing for $R$ |
| [`roxygen2`](https://cran.r-project.org/web/packages/roxygen2/vignettes/roxygen2.html) | In-Line Documentation for $R$ |
-------------------------------------
## Userful Packages on $GitHub$
First, make sure you have the `devtools` package installed on your computer *(hint: it is included in the list above)*.
```{r, eval=FALSE}
install.packages("devtools")
```
### Templates for writing tutorials, practicals or examination papers with $R Markdown$
`unilur` is a $R$ package to help writing tutorials, practicals or examination papers with $R Markdown$.
With `unilur` you can render the following outputs from a single rmarkdown file:
* the exam or tutorial questions (answers remaining hidden) as a PDF or HTML file.
* the exam or tutorial questions with sample answers as a PDF or HTML file.
In addition, you will be able to:
* Create coloured boxes to highlight some markdown or R content.
* Create examination papers with
+ multiple choice questions
+ a candidate identification form
+ dotted lines placeholders to fill in answers
* Create a new $R Markdown$ file with solution chunks replaced by empty ones.
```{block type='rmdlink', echo=TRUE}
Website: [GitHub - `unilur`](https://github.com/koncina/unilur)
Tutorial: [blog post - `unilur`](http://eric.koncina.eu/posts/introducing-the-unilur-rmarkdown-template/)
```
```{r, eval=FALSE}
devtools::install_github("koncina/unilur")
```
### Prepare APA journal articles with $R Markdown$
`papaja` is a $R$ package in the making including a $R Markdown$ template that can be used with (or without) **$R$ Studio** to produce documents, which conform to the **American Psychological Association (APA)** manuscript guidelines (6th Edition). The package uses the $LaTeX$ document class `apa6` and a .docx-reference file, so you can create PDF documents, or Word documents if you have to. Moreover, papaja supplies $R$ functions that facilitate reporting results of your analyses in accordance with APA guidelines.
`papaja` has not yet been submitted to $CRAN$ because it is under active development. Currently, there are still a couple of loose ends they would like to tie up before we release the package to a larger audience. There are two versions you can install from the $GitHub$ website.
```{block type='rmdlink', echo=TRUE}
Website: [GitHub - `papaja`](https://github.com/crsh/papaja)
Tutorial: [eBook - `papaja`](https://crsh.github.io/papaja_man/)
```
```{r, eval=FALSE}
# Install the stable development verions from GitHub
devtools::install_github("crsh/papaja")
# Install the latest development snapshot from GitHub
devtools::install_github("crsh/papaja@devel")
```