Install & Update



Install R


The R language and its tools are built by people from around the world. Together they help you perform data analysis in an easy to follow step-by-step fashion, much like you’re following a recipe for cookies. And once you find your favorite recipe, you can easily use it over again on new data or share it with your collaborators.

Windows

  1. Navigate to R’s download page -> Windows
  2. Click Download R 3.*.* for Windows
    • ex. R-3.5.*-win.exe
  3. Save the file and install with the default options.

For a video walk through see Installing R on Windows

Mac/Apple

  1. Navigate to R’s download page -> Mac
  2. Scroll down and download the first file under Latest release:
    • ex. R-3.5.*.pkg
  3. Save the file and install with the default options.

For a video walk through see Installing R on Mac

Linux

  1. Navigate to R’s download page -> Linux
  2. Choose your operating system.



Install RStudio


RStudio is the handy user interface we use to write R scripts and keep our projects organized. It isn’t required to use R, but it makes things a whole lot easier.

Install RStudio

  1. Open your web browser and navigate to www.rstudio.com
  2. Choose your operating system and download the newest version
  3. Open the file and install with the default options
  4. You are officially ready to R


Install R packages


R comes installed with many built-in functions and tools to help do your work. On top of this foundation, what is often referred to as base-R, contributors from around the world have created tools that make R easier and accomplish more with your data. These add-ons are called packages, and are made available to everyone to download for free. Below are a few examples, grouped into general categories.

Packages used in this training

Load data

readr Load data from text files: tab, comma, and other delimited files.
readxl Load data from Excel.
janitor Clean and simplify column names.


Manipulate data

dplyr Essential shortcuts to subset, summarize, rearrange, and join data sets.
tidyr Reshape tables and unpack multiple inputs stored in single cell.
stringr Tools to edit and clean text and character strings.
lubridate Tools to format dates and perform calculations based on time.


Charts and visuals

ggplot2 Essential package for plots and charts.


Maps

leaflet Display spatial data and make interactive maps.
sf Simple features, a spatial format using data frames to perform spatial.


General

devtools Install packages directly from other sources like GitHub.


But how?

To use a package you first need to install it – much like a free App for your phone. To get a jump start on the workshop, you can copy the text below and paste it into the RStudio console. The console is found on the left-side of the screen when you open RStudio.

new_packages <- c("readr", "readxl", "dplyr", "stringr", "tidyr",
                  "ggplot2", "lubridate", "janitor", "curl")

install.packages(new_packages)


Then press ENTER to begin the installation. If all goes well, you should start to see some messages appear similar to this, which provide information on the installation progress.


Try loading a package from your library to see if it installed correctly.

library(readr)


Additional recommended packages

Load data

RODBC Load data from Access and Oracle databases.
RMySQL, RPostgresSQL, and RSQLite for connecting to SQL databases.
pdftools Read PDF documents.
googledrive Read and write files to your Google Drive.
foreign Load data from Minitab and Systat.
R.matlab Load data from Matlab.
haven Load data from SAS, SPSS, and Stata.


Manipulate data

stringr Tools to edit and clean text and character strings.


Charts and visuals

ggsave Export charts in various formats and sizes.
openair For monitoring data visuals like wind roses and calendar plots. xkcd, hrbrthemes , ggpomological, ggthemes Chart themes for ggplot.
viridis, wesanderson, ghibli Color palettes.
rmarkdown Write summary reports and save as PDF, Word document, presentation, or website.


Maps

tidycensus Download Census and American Community Survey data.


Update R



The R software receives periodic updates about once a year. Windows users can update R with the installR package, and Mac users can use the updateR package. Linux users can go to the R Archive and follow the download links for their operating system.


Windows

  1. Run: install.packages("installr")
  2. Run: installr::updateR() to check for updates
    • Click Ok to begin installation
    • Click No to news
    • Click Yes to install
    • Click No to running updateR from the Rgui
    • Click Next and leave default options on each of the installation windows
    • Click Finish
  3. Yes to copy your R packages
  4. No to keeping a copy for the old R version
  5. No to copying your .Rprofile
  6. No to starting the Rgui
  7. No to quitting R
  8. Save any open R scripts
  9. Close and restart R

On Mac/Apple

# Get the devtools package
install.packages("devtools")

# Get the updateR package
devtools::install_github("andreacirilloac/updateR")

# Update R
updateR::updateR(admin_password = "Admin user password")


Update RStudio


You can check for RStudio updates from the Help menu in RStudio’s top navigation bar.

Instructions

  1. Open RStudio
  2. Click Help on the far right of the top navigation bar
  3. Select Check for Updates
  4. Follow the installation instructions


Update R packages


There are two places where you can update R packages within RStudio.


1. In the Files and Plots area in the bottom right, under the Packages tab:

Click the green Update button next to Install.


2. In the Tools tab above at the top above the Code Editor:

Choose the 2nd option -> “Check for Package Updates…”