Getting to know R, RStudio, and Quarto

Lucy D’Agostino McGowan

Agenda

  • Meet the toolkit
  • Demos
  • Lab 01 on your own

What is R?

  • scripting language
  • statistical software
  • like a car’s “engine”

What is RStudio?

  • IDE (integrated development environment)
  • like a car’s “dashboard”

Let’s take a tour – R / RStudio

What did we learn?

  • Using the console
  • Using R as a calculator
  • Environment
  • Loading and viewing a data frame
  • Creating a Project

R essentials

A short list (for now):

  • Functions are (most often) verbs, followed by what they will be applied to in parentheses:
do_this(to_this)
do_that(to_this, to_that, with_those)
  • Columns (variables) in data frames are accessed with $:
dataframe$var_name
  • Packages are installed with the install.packages function and loaded with the library function, once per session:
install.packages("package_name")
library(package_name)

tidyverse

R packages for data science

The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.

Quarto

Quarto

  • Fully reproducible reports – each time you render the document the analysis is run from the beginning
  • Simple markdown syntax for text
  • Code goes in chunks, defined by three backticks, narrative goes outside of chunks

Let’s take a tour - Quarto

What did we learn?

  • Creating a project
  • Creating a .qmd file
  • Rendering documents
  • Visual Editor
  • The YAML
  • Markdown and (some) R syntax

Rendering

Use the Render button in the RStudio IDE to render the file and preview the output with a single click or keyboard shortcut (⇧⌘K).

If you prefer to automatically render whenever you save, you can check the Render on Save option on the editor toolbar.

YAML header

The YAML header starts and ends with three dashes

---
title: "This is a title"
format: html
editor: visual
---

Code chunks

R code chunks identified with {r} with (optional) chunk options, in YAML style, identified by #| at the beginning of the line.

```{r}
#| label: load-packages
#| include: false
library(tidyverse)
library(palmerpenguins)
```

Would this code chunk be “included” in the final report?

Markdown text

  • Quarto uses markdown for formatting text, including section headers, hyperlinks, an embedded image, and an inline code chunk.
  • If you use the “visual” editor, you don’t need to learn much of this

Your turn

  • Log into RStudio Pro
  • Open the project you created in the last class
  • Explore the visual editor – try adding some bold text to the document
04:00

Workspaces

Remember this, and expect it to bite you a few times as you’re learning to work with Quarto: The workspace of your Quarto document is separate from the Console!

  • Run the following in the console
x <- 2
x * 3

All looks good, eh?

  • Then, add the following chunk in your Quarto document
x * 3

What happens? Why the error?

How will we use Quarto?

  • Every assignment / report / project / etc. is a Quarto document
  • You’ll often have a template Quarto document to start with
  • The amount of scaffolding in the template will decrease over the semester
  • You will turn in the .html file on Canvas

Lab 01

  • Lab instructions are posted on the course website under assignment
    • Let’s go find today’s!