-
Notifications
You must be signed in to change notification settings - Fork 15
/
packages.qmd
74 lines (45 loc) · 3.73 KB
/
packages.qmd
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
---
title: "R & RStudio, packages, tidyverse"
subtitle: "Downloading and installing"
date-modified: 'today'
date-format: long
license: CC BY-NC
bibliography: references.bib
---
## Download R & RStudio
R and RStudio are not the same thing. Both are open source applications and it is a good idea to have up-to-date installations. As of this writing, the easiest way to find both applications for local download are from the posit.co page. There are cloud versions of RStudio available for the Duke University community at the [VCM containers page](https://cmgr.oit.duke.edu/containers).
![Download R and RStudio](images/install_r.jpg)
## Install R, RStudio, R packages
After downloading R and R Studio, it's time to install each application. I recommend this Interactive [tutorial](https://tutorials.shinyapps.io/00-setup/ "how to install R, RStudio, and packages") for a guided overview of installing R, RStudio, and packages. A summary of installing packages is below.
## Packages
In R, a package is a collection of R functions, and/or data, and/or documentation. R users find and install packages via centralized package-hubs (e.g. [Metacran](https://www.r-pkg.org/), CRAN, [Bioconductor](https://bioconductor.org/), [R-universe](https://r-universe.dev/search/), Github) to aid in the specialization and efficiency of R coding.
Packages can be installed with the `install.packages()` function. Alternatively, from within RStudio \> Packages \> install
::: column-margin
```{=html}
<iframe width="300" height="200" src="https://www.youtube.com/embed/v4tmOymwznQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
```
:::
![Install packages](images/install_packages.jpg)
::: callout-important
## Install Once!
You only have to install a package once and should avoid putting the `install.packages()` function in your scripts. Of course, you will need to update packages from time to time.
:::
### Load packages
You should load packages at the top of your script. Write your script, then click the green arrow in the code-chunks; or Run All (Ctrl-Alt-R)
::: {layout-ncol="2"}
[![Load packages](images/packages_load.jpg){fig-alt="Load packages"}](images/packages_load.jpg)
[![Run packages](images/packages_run.jpg){fig-alt="Run packages" width="175"}](images/packages_run.jpg)
:::
## Tidyverse
![Tidyverse is a meta-package of several packages](images/package_tidyverse.jpg){style="float:right;"}
Tidyverse [@wickham2019] is a concept but also a package. When we load the tidyverse we load a meta-package that includes eight other packages. After the command load(tidyverse), there's no need to also load ggplot2, dplyr, lubridate or any of the packages. Those packages are included. Redundantly, it's fine to load the same package twice. Check the feedback from the code-chunk to see what is loaded by `library(tidyverse)`.
<br/>
> `install.packages("tidyverse")` (do once) <br/> <br/> `library(tidyverse)` (each session)
## Quarto installation
Quarto comes pre-installed with the latest versions of RStudio. However, if you want to install Quarto again, or for use with VSCode, learn how at [Quarto.org](https://quarto.org/docs/get-started/ "Get Started with Quarto")
::: {.callout-tip collapse="true"}
## What is Quarto?
[Quarto](https://quarto.org) is a scientific publishing system. As a next-genderation R Markdown, it offers new features, tight integration, and consistent documentation that make it a better choice for reproducible coding.
For example, Quarto can render documents in more output formats than R Markdown, including HTML, PDF, EPUB, and slides. The visual editor makes it easy to combine code, text, and figures in a single document.
:::
##