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.0, 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 1.1.447
, 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.
packages <- c( "devtools", "dplyr", "DT", "ggplot2", "ggpmisc", "kableExtra", "leaflet", "readxl", "remotes", "tidyr")
for (package in packages) { if (!(package %in% installed.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.2.4 Checking your package versions
We’ll be using the following package versions:
- devtools: version 1.13.5
- dplyr: version 0.7.4
- DT: version 0.4
- ggplot2: version 2.2.1
- ggpmisc: version 0.2.17
- kableExtra: version 0.8.0
- leaflet: version 2.0.0
- remotes: version 1.1.1
- readxl: version 1.1.0
- tidyr: version 0.8.0
Ideally, you should have the same versions installed. …but as long as your versions are not too far off, you should be okay. To check your versions, you can run the following snippet:
for (p in packages) {sprintf("%s: version %s", p, packageVersion(p)) %>% print()}
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.