# Getting set up for Labs in EDS 222

In EDS 222 labs, we will often be working with exercises based on *Introduction to Modern Statistics* by Çetinkaya-Rundel and Hardin. To be able to access the data and custom packages these exercises sometimes rely on, we need to do a bit of setup. This will get you all set for all future labs; you won't need to do it each time.

## Step 1: Create an RStudio project called `eds222_labs` where you will store all your lab materials for EDS 222. 

## Step 2: Download `_common.R` from our [course website](../labs/_common.R) and put it in the `eds222_labs` directory

## Step 3: Install the following packages, if they are not already installed:^[Note: This will take a minute or two!]

```{r setup, include=TRUE, echo=TRUE, eval=FALSE}
suppressMessages({
  install.packages(c(
    "tidymodels",
    "gghighlight",
    "glue",
    "ggmosaic",
    "ggridges",
    "gridExtra",
    "infer",
    "janitor",
    "knitr",
    "kableExtra",
    "maps",
    "openintro",
    "patchwork",
    "quantreg",
    "tidyverse",
    "scales",
    "skimr",
    "caret",
    "palmerpenguins",
    "survival",
    "waffle",
    "ggrepel",
    "ggpubr",
    "openintro",
    "here"
  ))
})
```

## Step 4: Load all the packages you need, plus the `_common.R` source file.^[Note: If you get a `namespace load` error for `tidyverse`, you want to remove the problem package, reinstall it, and then load `tidyverse` again.]

```{r, include=TRUE}

# You probably already have these packages installed, so let's just load them
library(tidyverse)
library(gt)
library(openintro)
library(here)
```

Take a look at the help files for `source()` and `file.path()` functions. We will use these a lot in Labs and homework assignments.

```{r,include=TRUE}
# `source()` is a helpful function for calling and running other R scripts.
?source

# `file.path` is a helpful function for calling file paths created previously (especially if you store your data on GDrive)
?file.path

# `here::here()` is a helpful function for creating file paths from directory and file names relative to your RStudio project
?here::here
```

Now, use `source` to run the script `_common.R`, which loads all the packages we'll need for our labs and does some extra stuff we won't use today. You'll `source()` this setup script before running all your labs.

```{r,include=TRUE}
source(here::here("course-materials", "labs", "_common.R"))
```

For labs, we want to see all our code. Set your `knitr` options to `echo=TRUE` so you see all your code and output.

```{r,include=TRUE}
knitr::opts_chunk$set(echo = TRUE)
```

Done! First real lab on Thursday in class. 

