R & RStudio, packages, tidyverse
Downloading and installing
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.
Install R, RStudio, R packages
After downloading R and R Studio, it’s time to install each application. I recommend this Interactive tutorial 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, CRAN, Bioconductor, R-universe, 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
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)
Tidyverse
Tidyverse (Wickham et al. 2019) 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)
.
install.packages("tidyverse")
(do once)
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
Quarto 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.