Configuring RStudio with GitHub
Getting Started
Below are instructions for setting up our course environment. We’re going to walk through them together, but different groups might get stuck at different points in the process. If you get stuck, hold up a block flag, which indicates to me that you need help.
Step 1: Create GitHub Account
You should create a GitHub account here. When choosing a username, I encourage you to:
- Include some version of your actual name
- Keep it short!
- Avoid including things that designate this moment in time. (Don’t include “Smith student” or “2022”)
Step 2: Install R
and RStudio
I’m assuming that everyone in this course already has R
and RStudio installed - either because you are in SDS 100, and you installed things yesterday, or because you’ve taken a course in R
before. If you haven’t installed R
and RStudio, follow these instructions to do so.
Step 3: Open RStudio
Note the different sections of the RStudio interface.
CONGRATULATIONS! You’ve installed all of the software needed for this course. Now onto configuration.
Step 4: Install git (OS-specific instructions below)
This is going to be different for different students depending on what type of operating system you are using. Scroll to the instructions for your operating system.
Step 4 for MacOSX
If you just recently installed RStudio, when you open RStudio, you may see a window that looks like this:
If you see this image, you should click ‘Install’. It will likely take a few moments to install.
If you don’t see this image, it could be because git is already installed on your computer. You can check by navigating to the ‘Console’ pane at the bottom of your screen and clicking on the ‘Terminal’ tab. Enter the following in that window: which git
. If git is not installed, the window will tell you so. If it is installed, it will report a file path. My file path looks like this: /usr/bin/git
, but yours may look different.
If git is not installed at this point, then you should copy and paste the following into your Terminal and click enter:
xcode-select --install
Step 4 for Windows
Check if git is already installed by navigating to the Console pane at the bottom of your screen and clicking on the ‘Terminal’ tab. Enter the following in the Terminal: where git
. If git is not installed, the window will tell you so. If it is installed, it will report a file path. My file path looks like this: /usr/bin/git
, but yours may look different.
If git is not installed at this point, then you should install Git for Windows here. When installing, you will be prompted about “Adjusting your PATH environment”. When this happens, you should select “Git from the command line and also from 3rd-party software”.
Step 5: Install usethis
Many of you will have already installed the usethis
package in SDS 100 yesterday. If for some reason you didn’t, you should follow the instructions below to install usethis
.
- Ensure that you are in the ‘Console’ at the bottom of your screen.
- Copy and paste
install.packages("usethis")
into your console and click enter. - You will be asked “Do you want to install from sources the packages which need compilation? (Yes/no/cancel)”, and you can type ‘no’. After that, a bunch of lines of code will run with red font.
Step 6: Configure git
Copy and paste
library(usethis)
into your Console to load the library.Copy and paste the following into your console, replacing USERNAMEHERE with your GitHub username and EMAILHERE with your GitHub email:
use_git_config(user.name = "USERNAMEHERE", user.email = "EMAILHERE")
Step 7: Create Personal Access Token
- Navigate to Github.com and log-in.
- At Github.com, click on your user icon (top right hand corner) and then ‘Settings’.
- At the very bottom of the left side panel, click ‘Developer Settings’
- In the right sidebar, click ‘Personal Access Tokens’, and then on the page that appears, click ‘Generate New Token’.
- In the ‘Note’ field, enter “SDS 192”
- Set the ‘Expiration’ to ‘Custom’, and then select a date after December 12, 2022.
- Check the box next to ‘repo’ in Select Scopes.
- Click the green ‘Generate Token’ button.
- Keep this window open because you will need to copy your Personal Access Token in the next step.
Step 8: Store your Personal Access Token in RStudio
- Install the
gitcreds
package by entering the following into your RStudio Console:install.packages("gitcreds")
- Load the
gitcreds
package by entering the following into your RStudio Console:library(gitcreds)
- Enter
gitcreds_set()
into your Console. - You will be prompted to enter your password or token. Head back over to Github.com, and copy the Personal Access Token that you created in the last step. It will be a long string of characters. Paste it into your RStudio Console.
CONGRATULATIONS! You’ve configured GitHub to connect with RStudio! Now onto assignment submission practice.
Step 9: Create first GitHub repo
In Moodle, scroll to today’s date to find the Course Infrastructure Set-up link. Click this link to enter our GitHub classroom. This will copy a GitHub template repo into your GitHub account. It might take a few moments.
Step 10: Copy repo URL
Once the repo is created, copy the link to the repo that was just created to your clipboard. It should look something like https://github.com/sds-192-intro-fall22/getting-started-YOUR-USER-NAME
Step 11: Create git Project in RStudio
- In RStudio, click File > New Project > Version Control > Git
- In the window that appears, paste the URL that you copied in the last step into the ‘Repository URL’ box.
- Where it says ‘Create project as subdirectory of:’, click ‘Browse’. Create a new folder called “SDS 192.” I suggest that you store this folder in you Documents folder, so that you can easily find it.
- Click ‘Create Project.’
Step 12: Open, edit, and commit changes to getting-started.qmd
On the initial install, the Files tab will be in the lower right hand corner of RStudio. Look for the
getting-started.qmd
file in that pane and then open it.Follow instructions in the file. Make sure to save the file.
When the file tells you to commit your code, turn your attention to the Environment pane of RStudio (i.e. upper right hand pane on initial install).
Click on the ‘Git’ tab, and then click the blank checkbox next to
getting-started.qmd
. As we will learn in a few weeks, this stages a file in git.In this same ‘Git’ pane, click the ‘Commit’ button. In the window that appears, you will be prompted to write a commit message. Enter the following in the commit message window: “added name to getting-started.qmd”
Click the ‘Commit’ button. Again, in a few weeks, we will learn what this means.
If you’ve done this correctly, when you close the window, there will be no files listed in the Git pane.
Step 13: Push your code to GitHub.com
In the same ‘Git’ pane, you will see a little green upwards arrow, click this arrow to push your code to GitHub.com.