Assignment 1 - Getting set up to use the command line and R

In this assignment, you will:


Installing the programs we will use in the course…

Install R

Use the following link to download R for your particular computer system: https://cran.r-project.org/


Install R-Studio

It’s a good idea to install R before installing R-Studio https://www.rstudio.com/products/rstudio/download/#download


Install Git

Here’s the download page: https://git-scm.com/downloads

If you are on a Windows computer, click the “Windows” button and your download should start automatically. Run the .exe file to install “Git Bash”

If you are on a Mac, click the “Mac” button and the .dmg file should download automatically. This will open in your software center and install.

If you are on Linux, here are the instructions, depending on your version: https://git-scm.com/download/linux


Copy a test github repository to your own computer

Once you have Git installed, open it up (in Windows this will be a shortcut called “Git Bash”, in Mac or Linux, just open your terminal -that scary command prompt- and it will be working in the background) You will see a simple command line interface that looks something like this:

Navigate to your computer Desktop using the command-line. If you’ve never done this before, here’s a nice introduction: https://computers.tutsplus.com/tutorials/navigating-the-terminal-a-gentle-introduction--mac-3855

Basically, you can enter commands to move into or out of directories and look at what files are present.

  • the command “ls” lists the files in your current directory
  • the command “pwd” shows you the PATH and name of your current directory
  • the command “cd” stands for ‘change directory’

Here’s an example output from those first two commands:

ls #this lists files in my current directory
## Assignment_1.html
## Assignment_1.rmd
## setup_git_credential_helper.R
pwd #this tells me what my current directory is
## /home/gzahn/Desktop/GIT_REPOSITORIES/gzahn.github.io/data-course/Repository/Assignments/Assignment_1

The “cd” command requires a bit more. You have to tell it what directory to change to…

Mac and Linux users can probably just type “cd ~/Desktop” and they will instantly be on their Desktop folder Windows file paths are a bit different, but it’s probably something like this:

cd C:\Users\YOUR_NAME\Desktop

Once you’re in your Desktop folder (you can check with “pwd”) copy and paste the following into your terminal:

git clone https://github.com/gzahn/Data_Course.git

This will download a folder onto your computer. It will be found wherever you were when you entered the previous command….so hopefully your Desktop.

If you have it, that means you successfully “cloned” my online repository onto your local computer. This “git clone WHATEVER_WEBSITE_ADDRESS” will be very useful to you in this class. It’s how you will access other materials from my GitHub repositories, including exams!

That takes care of the software installation and course materials. Now, you need to set up your own GitHub account online.


Your GitHub account

  1. Navigate online to https://github.com/ and sign up for a free account. Please choose a professional-sounding username. Don’t sign up as “PukeMonster55” or anything like that, because this username will be part of your personal website.

This GitHub account is a way for you to store version-controlled code, data, and even your personal website that you will build by the end of the semester. It’s something that you can put on your CV/Resume to demonstrate coding and data analysis ability. Save your password someplace safe. Don’t give it to anyone, including me.

I made a short video walkthrough of the following steps here: https://youtu.be/M9430_eGttI

  1. Create a new repository on your GitHub page called “Data_Course_YOURLASTNAME” (Not literally “YOURLASTNAME,” but your actual last name, in all-caps, no spaces)
  • Look for the “+” in the very top-right of the web page
  • Enter the name “Data_Course_YOURLASTNAME” where prompted (last name in all-caps, no spaces)
  • Leave the “Public” option checked
  • Be sure to check the box “Initialize this repository with a README”

See these instructions for setting up 2-factor authentication for RStudio.

Enable two-factor authentication

Use the LastPass or other 2FA App for your phone, give it your phone number as a backup, and save your account recovery codes somewhere very safe (gmail draft message?)

You will need to create a personal access token to use GitHub from the command line

SET YOUR PAT TO NEVER EXPIRE

Copy your token and paste it into a text document. To set it as an “environment variable” enter the following in your command-line terminal, replacing TOKEN with the actual token you received online and YOUR_GITHUB_USERNAME with your username (keep all quotes as-is):

    echo 'export GIT_PASSWORD="TOKEN"' >> ~/.bashrc
    
    echo 'export GIT_USERNAME="YOUR_GITHUB_USERNAME"' >> ~/.bashrc
    
    exec bash
    

You can now type the following to see/copy your command-line GitHub token:

    echo $GIT_PASSWORD

Now, make a new file called git_credential_helper.sh

In that plain-text file, paste the following (just 3 lines):

#!/bin/bash
echo username=$GIT_USERNAME
echo password=$GIT_PASSWORD

Save it in your $HOME directory

Final step… In your terminal, run the following line, which will tell git that whenever you are on this computer, to use that file to figure out your username and password:

git config --global credential.helper "/bin/bash ~/git_credential_helper.sh"

If you are using Windows, their recent update means that instead, you should use the following:

git config --global credential.helper manager

  1. In your terminal, navigate to your Desktop with the command-line again

  2. Now clone the github page you created (The one called Data_Course_YOURLASTNAME)

  • Hint: use the same “git clone” command as above, but modify the web address to your new GitHub repository (Copy and paste from the web browser) This will import the website repository onto your personal computer (as a git repository)
  • You now have two new folders on your desktop. One called “Data_Course” and one called “Data_Course_YOURLASTNAME”
  1. Navigate into this new repository (The one called Data_Course_YOURLASTNAME) and type the following commands in order:

    (actually, copy-paste is better than typing. Coders use CTRL-C / CTRL-V more than anything else!)

    (What?! It’s not pasting text into your terminal? Ah, use CTRL-SHIFT-V or SHIFT-INS to paste into your terminal!)

echo "This README file contains information about my uploaded assignments" >> README.md
git add README.md
git commit -m "1st commit"
git push
(Here it will ask for your GitHub userID and password....enter those when asked)
This series of commands commits your changes (Adding that text to the README.md file) 
and pushes the changes back onto the website version
  • Note that by “navigate” I mean in your terminal using the “cd” command
  1. Check back on your GitHub page online…if you see that new text (“This README file contains information about my uploaded assignments”) then you are finished!

  2. To get credit, upload a link to your GitHub repository to “Assignment 1” in Canvas. I’ll click on that and see whether your README.md file is correct.

You now have a copy of all the current course materials along with your own personal repository This GitHub repository is where you will keep projects you’re working on, notes, examples, data sets, etc.

Warning: I will be cloning all of your repositories onto my own computer to keep track of your course work So don’t write hate mail about me in files in that directory.

  1. To get FULL credit, I want you to make 10 separate changes to this README file and commit and push each one in turn. You can use a basic text editor to make additional changes if you like. Add whatever you want to it 10 times, saving and committing and pushing between each change. One of the changes you should make is that I want you to copy some course materials from “Data_Course” into your “Data_Course_LASTNAME” repository. You can click and drag them over there if you want. Whatever. But just take the following directories and copy them into your repository (then add/commit/push the new files to your online repo):
  • Assignments/
  • Code_Examples/
  • Data/
  • Exercises/
  • Readings/

The point of this is that this workflow (save, add, commit, push) needs to be muscle memory for you as we progress in the course. Doing it 40 times is much better than 10 times, but 10 is all I am requiring at this point.

We will discuss what is actually going on with all of this in class, but this is to test whether you can follow precise instructions and troubleshoot.

Don’t be afraid to ask others/instructor/Google for help with this!