1 Computing Setup
This chapter will provide some details for setting up your computing environment to begin programming in R.
After reading this chapter you should be able to:
- Install R.
- Install RStudio.
- Install R packages.
- Configure RStudio.
1.1 Operating System
We will support almost any operating system (OS), within reason, however we assume you will be using one of:
- Windows
- macOS
- Linux
For each, we assume that your OS is reasonably up-to-date.1
1.2 Install R
R (R Core Team 2022) is a freely available language and environment for statistical computing and graphics. Use the appropriate link from the following2 to download and install R:
1.3 Install RStudio
RStudio (RStudio Team 2020) is a free and open-source integrated development environment (IDE) for R. Use the link for “RStudio Desktop (Open Source License)” from the following4 to download and install RStudio:
1.4 Install Packages
The wonderful package system is a large part of what makes R a great language. To install several packages that we will need later, run the following code in R5:
install.packages("tidyverse")
To verify that this has worked, run the following:
library("tidyverse")
#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
#> ✔ dplyr 1.1.0 ✔ readr 2.1.4
#> ✔ forcats 1.0.0 ✔ stringr 1.5.0
#> ✔ ggplot2 3.4.1 ✔ tibble 3.2.1
#> ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
#> ✔ purrr 1.0.1
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
If you do so, and your output looks relatively similar, you have successfully installed all of the packages of the tidyverse
(Wickham et al. 2019).
We will further discuss installing and using packages later. For now, we’re mostly checking that your R and RStudio are setup correctly.
1.5 RStudio Setup
To see the wealth of ways that you can customize RStudio, take a look at Preferences. For example, many users prefer a dark theme. To change RStudio’s theme, see Appearance in the Preferences window.
In general, we advocate for keeping things as default as possible, however there are some noteworthy exceptions.6
1.5.1 Do Not Restore Old Workspaces
Due to some odd default settings in RStudio, some students never clear their R environment. This is a problem for a number of reasons.7 To avoid these issues, do the following:
- Clear your current environment.
- Change some RStudio defaults.
- Deselect “Restore .RData into workspace at startup.”
- Set “Save workspace .RData on exit:” to “Never”
We use “reasonably up-to-date” to mean that you are using the most recent “major” version of your operating system. At the very least, you should be apply all security patches for whatever “major” version of an OS you are using.↩︎
Linux users: We assume you can figure out how to do this without us providing the links.↩︎
Nickname: “Shortstop Beagle”↩︎
Linux users: Again, you’re on your own.↩︎
To do so, open RStudio and copy-paste the code into the “Console” panel, then press the
[return]
key, ⏎. More on this next chapter.↩︎If you are are student in STAT 385 and notice that the RStudio in the tutorial videos is setup differently than yours, and are interested in how to make the same modifications, please ask!↩︎
It could prevent your results from being reproducible. It could cause R to run very, very slowly.↩︎