R Intro

Lecture 2

Dr. Elijah Meyer

Duke University
STA 199 - Spring 2023

January 18th, 2023

Checklist

– Are you on Slack?

– Have you reserved a Duke container?

– Have you accepted your GitHub organization invite?

– Do you see ae-1 on GitHub? If so, clone it for class!

– Chat with me before or after class / send an email with your GitHub username if you do not see ae-01

Announcements

– Slack postings

– Lab 0

– AE grading (Drop/Add ends - 25th)

Clone ae-01

– If you have not accepted your GitHub invitation, you can’t do this

– If you don’t see ae-01 in your org, work with the people around you

– Chat with me after class / send an email with your GitHub username if you do not see ae-01

Demo: clone ae-01

Goals for today

Basics we will use throughout the semester

  • R and RStudio
  • Quarto Documents
  • More Practice
  • Train your brain.

What is R and RStudio?

– R is a statistical programming language

– RStudio is a convenient interface for R

R-layout

Warm Up Question

Please think through / write down what each line of code would produce.

Tip (and good practice): if you have questions about a function, use ?function.name to pull up the help page! If the help page is not helpful, look at their examples section and click Run Examples.

Some R essentials

Functions are (normally) verbs, followed by what they will be applied to in parentheses:

R essentials

Packages are installed with the install.packages function and loaded with the library function, once per session:

Packages

library(tidyverse)

Packages

library(tidyverse)

tidyverse

– The tidyverse is a collection of R packages designed for data science.

– All packages share an underlying philosophy and a common grammar.

GitHub: Version control

GitHub Commands: Pull Commit Push

GitHub Commands: Pull Commit Push

GitHub Commands: Pull Commit Push

Demo: Try it!

Quarto

– an open-source scientific and technical publishing system

– publish high-quality articles, reports, presentations, websites, blogs, and books in HTML, PDF, MS Word, ePub, and more

– Code goes in chunks, defined by three backticks, narrative goes outside of chunks

How will we use Quarto?

– Every assignment / lab / project will be given to you as a Quarto document

– You will always have a Quarto template document to start with

– As we get more familiar with R, the more code you will construct on your own

ae-01

Wrap up

– What is version control? Why is it important?

– What is R vs RStudio?

– What is Quarto?