9 Aloha R!

The first part of the lab, Aloha R, focuses on setting up GitHub, RStudio, and YAML while introducing the basics of R Markdown. This section supports the second goal of the Hello R lab. The goal is to get you comfortable with the tools you’ll be using throughout the course.

Getting started

Each of your assignments will begin with these initial steps. This lab provides a detailed overview of the process, but future labs will offer less detail. You can always refer back to this lab for a detailed list of the steps involved in getting started with an assignment.

  • You can find the assignment link for this lab here. This GitHub repository (“repo”) serves as a template for the assignment. You can build on it to complete your assignment.

  • First, log into your GitHub account. If you don’t have one, you can create one here, using your university email address.

  • Next, you need to get a copy of the lab repo on your own GitHub account. This is called “cloning” the repo. You can do this by clicking on the green “Use this template” button.

    • On GitHub, click on the Use this template button.
    • This option initiates the creation of a repo on your account, based on the lab template.

  • You should now provide a name to your new repository. Lab 01 or something to that effect should work nicely. You can also provide a description if you like. It’s not necessary, but it can be helpful to future you.

  • I recommend making the repo public, but private is fine if you already have GitHub pro set up.

  • Once you fill out all the required information, click on the Create Repository from Template button.

  • Now you should have your own copy of the lab!

  • Now we need to connect your new git repo with your computer.

  • Notice that are a few ways to interface between git and R.
    • Clone
    • Open
    • Download

Option 1: Use Github Desktop

Yoo Ri Hwang wrote up a lovely demo for how to get a lab via github desktop. Her example uses lab 02, but we can use it for lab 1 as well. For example, you might want to download lab-02-plastic-waste. First, create account/password in the Github, and install desktop Github app.

Go to your repositories

Click the new button.

Repositories template -> DS4P/lab-01-plastic-waste

You can create this repository.

Then, go to the repository that you’ve just created. Click code -> open with the GitHub Desktop.

Click Open GitHub Desktop

You can change the local path by clicking “choose”. And if you click the “clone” button, the lab02 plastic waste file would be in your local path.

Your changes should be automatically reflected in the app.

Write something in there (where I wrote “write something”) and click the “Commit to main” button.

  • Click the “Push Origin” button, and tada~

  • Hit OK, and you’re good to go!

Option 2: Use RStudio

Option 2
  • From your repo, select Code.

  • Use RStudio to clone the repo.

  • Now, select Use HTTPS (this might already be selected by default, and if it is, you’ll see the text Clone with HTTPS as in the image below). Click on the clipboard icon to copy the repo URL.

  • Go to RStudio. Select from the menu, new project.

  • Using the new project wizard, select Version Control

  • Select the option for Git

  • Copy and paste the URL of your assignment repo into the dialog box.

  • Fill out the information for what folder you’d like to store your lab in.

  • Hit OK, and you’re good to go!

Introduction to R and RStudio

Before we introduce the data, let’s warm up with some simple exercises.

FYI: The top portion of your R Markdown file (between the three dashed lines) is called YAML. It stands for “YAML Ain’t Markup Language”. It is a human friendly data serialization standard for all programming languages. All you need to know is that this area is called the YAML (we will refer to it as such) and that it contains meta information about your document.

YAML

Open the R Markdown (Rmd) file in your project, change the author name to your name, save your changes, and then knit the document.

Committing changes

Then go to the Git pane in your RStudio.

If you have made saved changes to your Rmd file, you should see it listed here. Click on it to select it in this list and then click on Diff. This shows you the difference between the last committed state of the document and its current state that includes your changes. If you’re happy with these changes, write “Update author name” in the Commit message box and hit Commit.

You do not have to commit after every change, indeed doing so would get quite cumbersome. You should consider committing states that are meaningful to you for inspection, comparison, or restoration. In the first few assignments, I’ll suggest exactly when to commit and in some cases, what commit message to use. As the semester progresses, you make these decisions.

Pushing changes

Now that you have made an update and committed this change, it’s time to push these changes to the web! Or more specifically, to your repo on GitHub. Why? So that others can see your changes. And by others, depending on your privacy settings, we mean the just you OR perhaps the world…

In order to push your changes to GitHub, click on Push. This will prompt a dialog box where you first need to enter your user name, and then your password. This might feel cumbersome. Soon – you will learn how to save your password so you don’t have to enter it every time. But for this one assignment you’ll have to manually enter each time you push in order to gain some experience with it.