3 RStudio and Git/GitHub Setup

3.1 Learning Objectives

In this lesson, you will learn:

  • How to check to make sure your RStudio environment is set up properly for analysis
  • How to set up git

3.2 Checking the RStudio environment

3.2.1 R Version

We will use R version 3.5.1, which you can download and install from CRAN. To check your version, run this in your RStudio console:

R.version$version.string

3.2.2 RStudio Version

First, lets make sure everyone’s RStudio is up to date. Run the following in your RStudio console:

RStudio.Version()$version

If the output of this does not say at least 1.1.4XX (current version is 1.1.456), you should update your RStudio. Do this by selecting Help -> Check for Updates and follow the prompts.

3.2.3 Package installation

Run the following lines to check that all of the packages we need for the training are installed on your computer, and update packages that are out of date.

packages <- c( "devtools", "dplyr", "DT", "ggplot2", "ggpmisc", 
               "kableExtra", "leaflet", "readxl", "remotes", "tidyr",
               "ggmap", "sf", "raster")
for (package in packages) { 
    if (!(package %in% installed.packages())) {install.packages(package)} 
    else if (package %in% old.packages()){install.packages(package)}
}


rm(packages) #remove variables from workspace

If you haven’t installed all of the packages, this will automatically start installing them. If they are installed, it won’t do anything.

Next, create a new R Markdown (File -> New File -> R Markdown). If you have never made an R Markdown document before, a dialog box will pop up asking if you wish to install the required packages. Click yes.

3.3 Setting up git

If you haven’t already, go to github.com and create an account. If you haven’t downloaded git already, you can download it here.

Before using git, you need to tell it who you are, also known as setting the global options. The only way to do this is through the command line. Newer versions of RStudio have a nice feature where you can open a terminal window in your RStudio session. Do this by selecting Tools -> Terminal -> New Terminal.

A terminal tab should now be open where your console usually is. To set the global options, type the following into the command prompt, with your actual name, and press enter:

git config --global user.name "Your Name"

Next, enter the following line, with the email address you used when you created your account on github.com:

git config --global user.email "yourEmail@emaildomain.com"

Note that these lines need to be run one at a time.

Finally, check to make sure everything looks correct by entering this line, which will return the options that you have set.

git config --global --list

3.3.1 Note for Windows Users

If you get “command not found” (or similar) when you try these steps through the RStudio terminal tab, you may need to set the type of terminal that gets launched by RStudio. Under some git install senerios, the git executable may not be available to the default terminal type.