Technologies, Data, and Stat Learning Methods

Stat 243: Lab 1

Due: Friday, Sep 18th, 11am PT.

Introduction

R is a wonderful programming language that we will frequently use in our course to visualize and tidy data, create programs to assist computations, create data models, and perform statistical inference. It is free, open-source, and has a large community of users who care about statistics and data science.

To begin, note that there are 3 closely related computer processes that we will work with: R, RStudio (or Positron), and Quarto. It’s worth taking a moment to distinguish between them.

  • R is a programming language, which can be accessed by typing particular commands into the console or at the command prompt.
  • RStudio and Positron are integrated development environments (IDEs), and provides a clean user interface for writing and executing R code. IDEs are the main tool we will use to interact with the R language.
  • Quarto is a file type we’ll use to write R code and text (similar to .docx, but for programming!). It can record R code, text, and graphical outputs. One of the easiest ways to share your results with others is to distribute your Quarto (or .qmd) file. It’s a “one-stop shop” of statistical work!

RStudio comes in two varieties: RStudio Desktop and RStudio Server. The desktop version is a program you can install on your personal computer, and uses your computer’s resources to perform calculations. For class purposes, we highly recommend RStudio Desktop (or Positron, the newer IDE from Posit that is also available in a Desktop version).

Problem 1: Setup

part a: GitHub

We’ll use GitHub for collaboration and portfolio building, so each of you need to have a GitHub profile. If you don’t have a GitHub profile already, go to https://github.com/ and sign up for one. Once you’ve signed up for an account, please add it to the Google Sheet so that I can add you to the stat-243-f26 organization. Note: you’ll need to be logged in to your Reed Google account to edit the Google Sheet.

part b: R and RStudio (or Positron!)

We’ll use R and RStudio/Positron for computing in this class. R is a statistical programming language, while RStudio and Positron are Integrated Development Environments (IDEs) that allow you to run R, view files, view R code output, and much more! Reed has an RStudio Server where you can run R and RStudio in the cloud, but for this class I would recommend a local installation of both R and RStudio. Positron is a new IDE from Posit (the company that makes RStudio) you are welcomed and encouraged to try out Positron, although I may not be able to provide as good of problem solving for any issues related to your IDE if you use Positron. Positron seems to be the hot new thing, and I imagine in the next ~5 years we will see a steep decline of RStudio use in favor of Positron for R users and data scientists.

To install R and RStudio, follow the directions from Posit’s website.

To install Positron, see this link from Posit’s website.

Note: always make sure to have R installed before installing your IDE.

part c: Connect git, GitHub and RStudio (or Positron)

These instructions are based on pieces of Happy git with R, in particular chapters 6, 7, and 9. Depending on your computer, setup, or just luck, this step can become difficult/frustrating. If you are having trouble with this step, please ask for help!

In order to have your computer talk with GitHub, you’ll need to install git on your computer. Sometimes, git is already installed on your computer, and you can check it by running

which git

in a Terminal or shell window. If you have git installed, you should see something like “/usr/bin/git” returned to you. If you don’t have git installed, you might see something like “git: command not found” or nothing at all. If you have git installed, congrats! If not, follow the steps in Happy git with R, Chapter 6 to install git.

NOTICE: PARTS d, e, and f are OPTIONAL!

If you would like to set up your GitHub account with your computer, complete steps d, e, and f. This will not be relevant to our class, though, so it is entirely optional. You are welcome to come to office hours for help completing steps d, e, and f. 

In order to get everyone set up in a reasonable amount of time during lab, we recommend skipping these steps for now. You are welcome to return to them after our in-class lab time.

part d: Introduce yourself to git

Next, up you have to introduce yourself to git. Again, following Happy git with R, in Chapter 7 we can run the following in an R session/console

## install if needed (do this exactly once):
## install.packages("usethis")

library(usethis)
use_git_config(user.name = "Jane Doe", user.email = "jane@example.org")

where Jane Doe is replaced with your full name and jane@example.org is replaced with the email you used to sign up for GitHub.

Next, you’ll have to authenticate yourself (i.e., give your computer permission to make changes to GitHub projects when you ask it to). To do this, run the following in an R session/console:

usethis::create_github_token()

This should open a new browser window where you can create your token. I often set no expiration date and check all of the boxes, but that is up to you. Note that when your token expires you’ll have to make a new one if you’re still using the same computer. Now, your token is created (it will start with “ghp_”)! Copy it down somewhere so that you don’t lose it.

The final step is to run

## install if needed (do this exactly once):
## install.packages("gitcreds")

gitcreds::gitcreds_set()

and then enter the token when prompted. If also this has gone well, you are set!

Unless… you’re running Linux. If you’re running Linux, I am happy to help you get git working correctly, but I’d say the first step is to read and follow Danielle Navarro’s blog post, in addition to the steps above.

part e: testing

To make sure everything is working correctly, run

gitcreds::gitcreds_get()

in an R session/console. You should see something like

<gitcreds>
  protocol: https
  host    : github.com
  username: PersonalAccessToken
  password: <-- hidden -->

but if you see

Error in throw(new_error("gitcreds_no_credentials", url = url)) : 
  Could not find any credentials

something has gone wrong.

part f: congrats!

If you’ve made it this far, congrats! You’ve successfully set up git, GitHub, and your IDE on your local machine! We’ll spend time in class during week 2 talking about how to use all of these tools, but for now you are good to go.

If you’ve had trouble with any of these steps, please come to office hours so that we can debug and get you set up.

Problems 2 and beyond

In order to access the next problems, clone the following repo:

https://github.com/stat-243-f26/lab01.git

For instructions on cloning a repo, see Lab Instructions

From there, you can answer the questions and then Render the document to submit the PDF to Gradescope.