Reference
Contents
Installing R and R Studio
- Install R from CRANThe Comprehensive R Archive Network
by clicking “Download R” (or the CRAN link under Downloads on the left menu). This will take you to a mirrors page, where you can select a location in the U.S. and download a copy of R - Install R Studio (Desktop Version), choose the “Free” option
R Packages
Packages come from multiple sources.
The polished, publicly released versions are found on CRAN. When installing a package available on CRAN, it is sufficient simply to tell R the following:Note the plural s on packages, and the quotes around the “package name”
Other packages, which may be in various developmental states (including perfectly functional!) are often hosted on GitHub before they make their way onto CRAN. Simply telling R install.packages("packagename") will fail to find it (as R only looks in CRAN for packages), so you must use another package called devtoolsWhich you will need to install first if you (probably) don’t already have it!
to install packages directly from Github:Note the :: allows you to use the function install_github() from the devtools package without having to first load the devtools package with library(devtools).
For example, to install Hadley Wickham’s package r4ds from its Github page https://github.com/hadley/r4ds, we would type:
Getting Help for R
For specific functions or commands, you can simply type:
This will display a help page specific to that function in the Viewer pane. R functions and packages are extremely well-documented; help pages normally include a short description of the function, arguments and options (as well as their default values), and several examples or vignettes to demonstrate usage of the function.
Additionally, you can turn to the community.
R Markdown
Math and LATEX
Math in R Markdown uses the LATEX language to typeset beautiful formulas and equations. To include mathematical symbols or expressions inlineThat means, within the text, and not in a separate line, location, or environment within the document.
, insert it $between two dollar signs$. Within a sentence, $2^2+\frac{\pi}{\pi}=5$ becomes 22+ππ=5.
If you prefer it to be centered in its own line, put it on its own line, $$between two dollar signs$$.
`‘‘2^2+\frac{\pi}{\pi}=5‘‘ becomes:
22+ππ=5
There is also a shortcut with the R package equatiomatic.
Producing documents
Producing a PDF Output
PDFs are archaic document formats with many flaws, yet the format remains the industry standard in most cases. PDFs are made with LATEX, a typography language dating to the 1980s. LATEX has its own problems
One alternative is tinytex
Resources
Cheat Sheets
R Packages
The following is a compendium of all R packages used, and their main uses
tidyverseDTknitrhavenreadxldplyrggplot2carsandwichlmtestequatiomaticgganimatestargazerbroommodelrinferaer
Finding Data
- A near-comprehensive list of all existing data sets built-in to R or R packagesNote: You should use these more for playing around with in R to boost your data wrangling skills. These should not be used for your projects in most circumstances.
Citations and bibliography
You can open the file in BibDesk on macOS, JabRef on Windows, or Zotero or Mendeley online.
You can download a BibTeX file of all the non-web-based readings in the course.