Problem Set 1

Total points: 20

Due by 23:59 on Tuesday, September 12, 2023

This homework helps you with establishing the workflow with GitHub and Rstudio, as well as guides you through the first steps in working with Quarto documents and writing code with R.

Task 1: Install the software (3 points)

If you haven’t done so, please install the software following the guidelines on this page. Do this as soon as you have the chance, ideally before Friday so you can come to the office hours if you need help.

Task 2: Load your first homework repo (2 points)

You will be working on homework assignments in private repositories, which means only you and I have access to the files. Each homework repo will include your GitHub login in the title. You should be able to load this repo into your local machine, make changes to the files there, and have access to uploading things back to GitHub (aka you will be able to “push”) so I can see and grade them.

Get the URL of the repo for homework assignment

Go to the page of our course organization on GitHub and open the repository PS01-[username]. This repo contains all the relevant materials for your first homework assignment.

Click on the green Code button and copy the HTTPS link for the repo by clicking on the clipboard icon.

Import the repository in RStudio

  1. Open RStudio and select File > New Project > Version Control > Git.

  1. In the final window, paste the repo URL you grabbed from GitHub in the Repository URL window. Click on Browse to select the folder on your computer where you want to store the project. I suggest you set up a folder on your computer for all the class content and always use this as a destination to store your material for the course.

Sometimes RStudio (and other programs as well) has troubles with paths that contain spaces or special characters, like umlauts (e.g., Ü). To avoid these problems, make sure your path to the project folder does not contain special characters and/or spaces.1 You can replace spaces in a file names and folders with dashes (-) or underscores (_) or remove them completely. Also, better avoid periods (.) in files’/folders’ names: periods should be saved for extension only.

  1. Click on Create Project.

If everything worked fine, you should now have a subfolder PS01-[username] in the folder our selected when downloading (aka “cloning”) the project.

Task 3: Practice committing to the repo (2 points)

Before we move to R, let’s try uploading files into GitHub. The process here requires two steps: first, you need to, figuratively, take a snapshot of your project looks like at the moment. This is what a commit command will do. And after that, you will need to upload your changes to GitHub (otherwise, they just stay on your local machine). This is done with the help of push command.

Make some changes

Your first commit will be adding your name to the YAML of the qmd file. Open the qmd and update the name on the top of the document. Don’t forget to save your changes (Ctrl + S/Cmd + S or the save button).

Now you are ready to make your first commit! Here are the steps you need to follow:

Upload the assignment to GitHub

  1. Switch to Git pane from the Environment pane in the upper right. If nothing appears in the Git pane in RStudio, click on Refresh button.

  2. Check all boxes that appear in the upper left pane next to files. By doing so, you are telling git which files you want to take a snapshot of (it doesn’t always have to be all files you made changes to). In git lingo, this means moving the files into Staging Area.

  3. Click on Commit to open the dialog window. Note that for you, it will be the qmd file that is showing up there, not the data as shown on the image.

  1. Write a Commit Message in the window. For this task, please use “Add my name” as your commit message. Usually, this should describe the work you did since your last commit so that at a later point in time, you can easily keep track of your process.

  2. Click on Commit. By doing so, you are telling git to take a snapshot of the files you selected.

  1. If everything worked fine, you should see something similar in a dialog window. This means that you have successfully saved your work and the “snapshot” on your computer.

  1. You can now see that there are commits that have not been uploaded to GitHub thanks to the message on the left: Your branch is ahead of ‘origin/main’ by 1 commit. Click on Push to upload the latest “snapshot” version to GitHub.

  1. If everything goes well, you will something resembling this message in a dialog window. You’ve done with the first commit 🎉

Now you can go to the repository on GitHub and check whether it is updated to the most current version of your assignment.

In a few minutes after you pushed, if you have done everything right, you will see the badge “Data folder commit” in the README.md (aka description) part in your repository turning green.

Task 4: Try working with Quarto document (11 points)

Now let’s move to the fun part–working in Quarto and writing the R code.

Open the file problem_set.qmd. This is the file that allows you to both write the code and the text, so you can produce well-formatted reports. Complete the tasks written in the file. You do not have to commit/push the work in progress, but you are more then welcome to!

Note: click on Save to see the changed files in the git pane.

Task 5: Commit and push the final result version to GitHub (2 points)

You’re almost done with the first homework! Now all that’s left is uploading the task back to GitHub. Essentially, you need to repeat the steps from before:

  1. Switch to Git pane from the Environment pane in the upper right.

  2. Check all boxes that appear in the upper left pane. By doing so, you are telling git which files you want to take a snapshot of (it doesn’t always have to be all files you made changes to).

  3. Click on Commit to open the dialog window.

  4. Write a Commit Message. For this task, please use “Final version” as your commit message.

  5. Click on Commit. By doing so, you are telling git to take a snapshot of the files you selected.

  6. If everything worked fine, you should see something similar in a dialog window. This means that you have successfully svaed your work on your computer.

  7. You can now see that there are commits that have not been uploaded to GitHub thanks to the message on the left. Click on Push in order to push the latest saved version to GitHub.

  8. If everything goes well, you will something resembling this message in a dialog window.

Congrats! You are done with the first homework assignment! 🎉

Footnotes

  1. For some general advice on file/folder naming, have a look here.↩︎