# Setup {.unnumbered}

## Installing R and RStudio

[R](https://cran.r-project.org/) is a programming language optimized for statistics and data analysis. Most people use R from [RStudio](https://rstudio.com/), a graphical user interface (GUI) that includes a file pane, a graphics pane, and other goodies. Both R and RStudio are open source, i.e., free as in beer and free as in freedom!

Your first steps should be to install R and RStudio, in that order (if you have installed these programs before, make sure that your versions are up-to-date---if they are not, simply follow the instructions below to re-install them):

1.  Download and install R from [the official website, CRAN](https://cran.r-project.org/). Click on "Download R for \<Windows/MacOS\>" and follow the instructions. If you have a Mac, make sure to select the version appropriate for your system (Apple Silicon for newer M1/M2/M3 Macs and Intel for older Macs).

2.  Download and install RStudio from [the official website](https://posit.co/download/rstudio-desktop/). Scroll down and select the installer for your operating system (most likely the .exe for Windows 10/11 or the .dmg for macOS 12+).

After these two steps, you can open RStudio in your system, as you would with any program. You should see something like this:

![How RStudio looks after a clean installation.](images/rstudio_first.png){#fig-rstudio-first}

::: callout-note
## Note for Windows users

While the installation steps above should be enough for most tasks, we also suggest that Windows users install [RTools](https://cran.r-project.org/bin/windows/Rtools/rtools44/rtools.html) (click on the "Rtools44 installer" link at the middle of the package to get the .exe file). Rtools is needed on Windows to install some advanced packages, so it is a good idea to have it on your system.
:::

That's it for the installation! We also *strongly* recommend that you change a couple of RStudio's default settings.[^00_setup-1] You can change settings by clicking on `Tools > Global Options` in the menubar. Here are our recommendations:

[^00_setup-1]: The idea behind these settings (or at least the first two) is to force R to start from scratch with each new session. No lingering objects from previous coding sessions avoids misunderstandings and helps with reproducibility!

-   `General > Uncheck "Restore .RData into workspace at startup"`

-   `General > Save workspace to .RData on Exit > Select "Never"`

-   `Code > Check "Use native pipe operator"`

-   `Tools > Global Options > Appearance` to change to a dark theme, if you want! Pros: better for night sessions, hacker vibes...

## Setting up for Methods Camp

All materials for Methods Camp are both on this website and available as [RStudio projects](https://support.posit.co/hc/en-us/articles/200526207-Using-RStudio-Projects) for you to execute locally. An RStudio project is simply a folder where one keeps scripts, datasets, and other files needed for a data analysis project.

Below are RStudio projects for you to download, available as .zip compressed files. On MacOS, the file will be uncompressed automatically. On Windows, you should do `Right click > Extract all`.

-   [Download Part 1 of the class materials](materials/methodscamp_part1.zip).
-   [Download Part 2 of the class materials](materials/methodscamp_part2.zip).
-   [Download Part 3 of the class materials](materials/methodscamp_part3.zip).
-   [Download Part 4 of the class materials](materials/methodscamp_part4.zip).

::: callout-warning
Make sure to properly unzip the materials. Double-clicking the .zip file on most Windows systems *will not* unzip the folder---you must do `Right click > Extract all`.
:::

You should now have a folder called `methodscamp_part1/` on your computer. Navigate to the `methodscamp_part1.Rproj` file within it and open it. RStudio should open the project right away. You should see `methodscamp_part1` on the top-right of RStudio---this indicates that you are working in our RStudio project.

![How the bottom-right corner of RStudio looks after opening our project.](images/rstudio_project.png){#fig-rstudio-project}

That's all for setup! We can now start coding. After opening our RStudio project, we'll begin by opening the `01_r_intro.qmd` file from the "Files" panel, in the bottom-right portion of RStudio. This is a Quarto document,[^00_setup-2] which contains both code and explanations (you can also read the materials in the next chapter of this website).

[^00_setup-2]: Perhaps you have used [R Markdown](https://rmarkdown.rstudio.com/) before. [Quarto](https://quarto.org/) is the next iteration of R Markdown, and is both more flexible and more powerful!
