1 Setup
Your project work starts here. Setup involves:
- Installing R and RStudio
- Installing the required R packages
- Creating the required directory structure
- Downloading the file packs and sorting their contents into the right places
- Creating an “R Project” (
.Rprojfile) to govern your project work - Successfully running the setup-check script
Setup activities typically take 30 minutes to an hour.
Don’t rush this process. Almost every “my project won’t knit” message we get traces back to a setup problem. Make sure you pass the setup check before you move on.
1.1 Install R and RStudio
If you haven’t already, Install R and then install RStudio. Below are step-by-step guides for Windows and macOS.
1.1.1 Windows
Step 1: Install R
- Go to the CRAN R Project website.
- Click on “Download R for Windows”.
- Click on “base” and then select the link labeled “Download R x.x.x for Windows” (where x.x.x is the latest version).
- Open the downloaded
.exefile and follow the installation prompts, accepting the defaults.
Step 2: Install RStudio
- Visit the RStudio download page.
- Click the link to download the Windows installer.
- Open the downloaded
.exefile and complete the installation using default settings.
Step 3: Verify the installation
- Launch RStudio from the Start menu or desktop shortcut.
- In the Console pane, type
print("Hello, world!")and press Enter. - If you see
[1] "Hello, world!", your installation is successful.
1.1.2 macOS
First, identify your Mac’s chip. Newer Macs use Apple Silicon (M1, M2, M3, M4, etc.); older ones use Intel processors. You need to know which you have to pick the right R installer.
- Click the Apple menu (top-left corner) → About This Mac.
- Look at the Chip (Apple Silicon) or Processor (Intel) line:
- If it says “Apple M1”, “M2”, “M3”, “M4”, or any Apple-labeled chip, you have Apple Silicon. You want the
arm64installer. - If it says “Intel Core …”, you have an Intel Mac. You want the
x86_64installer.
- If it says “Apple M1”, “M2”, “M3”, “M4”, or any Apple-labeled chip, you have Apple Silicon. You want the
Step 1: Install R
- Visit the CRAN R Project website.
- Click on “Download R for macOS”.
- Select the latest version matching your chip — either
R-x.x.x-arm64.pkg(Apple Silicon) orR-x.x.x-x86_64.pkg(Intel). - Open the downloaded
.pkgfile and follow the installation prompts.
Step 2: Install RStudio
- Go to the RStudio download page.
- Click the link to download the macOS version of RStudio.
- Open the downloaded
.dmgfile and drag the RStudio icon to yourApplicationsfolder.
Step 3: Verify the installation
- Open RStudio from your
Applicationsfolder. - In the Console pane, type
print("Hello, world!")and press Return. - If you see
[1] "Hello, world!", your installation is successful.
1.2 Install the required R packages
Now, install the seven packages required by the project.
Select the Packages tab in the bottom-right pane.
Click Install at the top of that pane.
In the “Install Packages” box, enter the package names separated by spaces or commas:
here tidyverse modelsummary ggpmisc car ggrepel kableExtraMake sure Install dependencies is checked.
Click Install.
You install packages only once per machine. Once installed, you “attach” them to a script (.R) or an R Markdown (.Rmd) using the library() function. The requisite library() calls are already included in the setup chunk of the project.Rmd template. Do not edit the setup chunk.
1.3 Create the required directory or folder structure
1.3.1 Make a BUSN 5000 folder first
Before building the project directory structure, you need to set up a top-level BUSN 5000 folder first. If you are new at this sort of thing, put it on your desktop. Otherwise, put it somewhere inside the Documents folder that makes sense to you.
Inside BUSN 5000, create two subfolders:
BUSN 5000/
├── Homework/
└── Project/
Homework/is where you’ll save completed homework assignments.Project/is the self-contained working directory for all project-related files.
The next step is creating the required structure inside of Project/. We won’t have anything more to say about the Homework/ directory in this guide.
1.3.2 Create the required subfolders inside Project/
The required directory structure has two levels – a main project folder, which you just created, and these five subfolders:
data/contains input data setsdata_documentation/contains the data documentation fileout/contains outputs generated by the scriptr/contains the R script that produces outputscss/contains the CSS (cascading style sheet) file that styles the slide deck
After creating the five subfolders, your project directory should look like this:
BUSN 5000/
├── Homework/
└── Project/
├── data/
├── data_documentation/
├── out/
├── r/
└── css/
You’ll put files into these subfolders in the next step. The .Rmd files themselves will live in the Project/ root, not in any of the subfolders.
1.4 Download the Pre-project file pack and sort its contents
Your project work starts with the Pre-project Exercise, so you’ll download the Pre-project file pack from eLC first. It is a .zip file containing the seven files required to complete the Pre-project Exercise:
pre_project.Rmd— R Markdown template for the Pre-project ExerciseLF.R— R script that producesLF.csv
project_slidedeck.css— the CSS file that styles the slide deckpppub24.csv— March 2024 CPS person-level data filehhpub24.csv— March 2024 CPS household-level data filecpsmar24_documentation.pdf— March 2024 CPS documentation filecheck_setup_preproject.R— R script that checks your setup for the Pre-project Exercise
Download and move the .zip file into your Project/ folder and unzip it. Sort the files from the unzipped folder into the right subfolders in your Project/ directory.
The Main Project requires a few additional files that are bundled in another file pack. We will cover those in the Main Project section of this guide.
Here is where each file goes:
| File | Goes in |
|---|---|
pre_project.Rmd |
Project/ (root) |
LF.R |
Project/r/ |
project_slidedeck.css |
Project/css/ |
pppub24.csv |
Project/data/ |
hhpub24.csv |
Project/data/ |
cpsmar24_documentation.pdf |
Project/data_documentation/ |
check_setup_preproject.R |
Project/r/ |
After sorting each file into its proper location, your Project folder should look like this:
Project/
├── pre_project.Rmd
├── data/
│ ├── pppub24.csv
│ └── hhpub24.csv
├── data_documentation/
│ └── cpsmar24_documentation.pdf
├── out/
│ (empty for now — LF.R will write LF.csv here)
├── r/
│ ├── LF.R
│ └── check_setup_preproject.R
└── css/
└── project_slidedeck.css
1.5 Create an R Project in the Project directory
Creating an R Project turns your Project/ folder into a single, self-contained workspace: every time you open it by double-clicking the .Rproj file, RStudio automatically makes that folder your working directory. That is what lets the here() paths in the scripts and the R Markdown template find your data and output files reliably – without it, RStudio has no fixed sense of where your project lives, which is the source of the cryptic “file not found” errors that come from running things out of your Downloads folder.
To create your R Project, follow these steps:
- Open RStudio.
- Go to File → New Project.
- Choose Existing Directory.
- Browse to your
Project/folder and click Create Project. - RStudio re-opens in your
Projectfolder loaded as the active project.
Creating the R Project writes the file Project.Rproj in the Project/ root. After creating the R Project, always, always, always open RStudio by double-clicking the Project.Rproj file.
1.6 Run the setup check
After completing the above steps, run the setup-check script to confirm everything is in place. It checks for the presence of all required files and confirms that they are in the right places. If you have any setup problems, it will tell you what they are and how to fix them.
To run the setup check script:
- Go to the Files tab in the bottom-right pane of RStudio.
- Click the
r/subfolder. - Click the file
check_setup_preproject.Rto open it in the editor. - In the editor, select all lines using Ctrl+A on Windows or Cmd+A on a Mac.
- Click the Run button in the top-right of the editor pane.
The script’s output appears under the Console tab in the pane below the editor, indicating whether each required file is in place — one line per file, marked either ✓ (good) or ✗ with a specific instruction telling you what to fix. Do not proceed until every line is a ✓.
1.7 Common errors
In our experience, these are three common setup errors, each of which is easily preventable.
project_slidedeck.cssin the wrong folderThe CSS file styles your slide deck. If it’s anywhere but
Project/css/project_slidedeck.css, your knitted slides will not be format compliant and your submission will be rejected. The setup-check script will catch this, so there should be no excuse for not correcting the problem.Working from your
DownloadsfolderIf you launch a script or R Markdown file from your
Downloadsfolder, RStudio’s working directory will beDownloads, not yourProject/folder and you will get cryptic “file not found” errors when the script or R Markdown tries to read files usinghere(). This occurs when you download the file pack intoDownloadsand then open the files directly from there.Knitting the R Markdown before running the R script
Knitting
pre-project.Rmdbefore runningLF.Rwill generate a fatal error because the Rmd readsout/LF.csv, which doesn’t exist until you runLF.R. The setup-check script confirms thatLF.Rexists, but it can’t confirm that it actually producedLF.csv. Only running the script can confirm that.
1.8 What happens next
When you are set up, continue to the Pre-project Exercise. After completing the Pre-project Exercise, you will be ready to work on the Main Project without any additional setup.