Chapter 1 Setup
1.1 What you need
To work through this book, you will need:
- Access to R/RStudio
- An internet connection (for installing packages)
- A basic familiarity with saving and opening files on your computer
1.2 R and RStudio (quick overview)
R is the language that runs your analysis. RStudio is the interface you use to write code, run code, view plots, and manage files. You have three options for using R/RStudio:
- Use OSC Classroom On Demand
Using the OSC Classroom on Demand is by far the easiest way to use R/RStudio for this course. All packages (see below for more info on packages) should already be loaded and tested to ensure compatability. - Install on your own machine
This option involves two steps. First, install “base” R from the Comprehensive R Archive Network (CRAN): https://cran.r-project.org/. Second, install RStudio: https://posit.co/download/rstudio-desktop/#download. - Use a computer in an on-campus computer lab.
This option should be considered a last resort. I cannot guarantee all packages will be able to be installed on university machines, and you would need to install the packages every time you use the machine.
1.4 Installing and loading packages
Packages extend R. You typically:
- Install a package once per computer
- Load the package each time you start a new R session
1.5 Installing the MKT4320BGSU package
The MKT4320BGSU package contains the functions and datasets used throughout this course.
1.5.3 Verify everything works
If the chunks below run without errors, you are set.
# A tibble: 6 × 5
userid age buy gender salary
<dbl> <dbl> <fct> <fct> <dbl>
1 15624510 19 No Male 19
2 15810944 35 No Male 20
3 15668575 26 No Female 43
4 15603246 27 No Female 57
5 15804002 19 No Male 76
6 15728773 27 No Male 58
1.6 R Notebooks (How You Will Complete Assignments)
All lab assignments in this course will be completed using R Notebooks (.Rmd files).
An R Notebook combines:
- Written answers (text you type)
- R code (that you run)
- Output (tables, plots, results)
into a single, reproducible document.
You will submit your completed notebook file for grading.
1.6.1 What Is an R Notebook?
An R Notebook is a special type of document that lets you:
- Write explanations in plain text
- Run R code in chunks
- See results immediately below the code
- Save everything in one file
Conceptually, think of it as:
A Word document + an R script + your results, all in one place
This is how professional analysts document their work.
1.6.2 The Assignment Workflow
For each lab assignment, you will:
- Use the provided notebook template in RStudio (for example:
LA01WriteUp.Rmd) - Work inside the existing structure
- Add:
- Code inside code chunks
- Written answers under the Answers sections
- Save the file
- Submit the
.Rmdfile in Canvas
You should not delete chunk labels, headings, or instructions unless explicitly told to do so.
1.6.3 Code Chunks (Very Important)
Code in an R Notebook lives inside code chunks, which look like this:
``` r
# Your code goes here
```
Each chunk:
- Has a label (for example,
q1) - Runs independently
- Produces output directly below it
You should only put R code inside code chunks.
1.6.4 Running Code While You Work
While completing assignments, you will primarily run code one chunk at a time or line-by-line inside code chunks.
Use:
- Run → Run Current Chunk, or
Ctrl + Shift + Enterline-by-line
Running chunks:
- Shows output immediately
- Helps you debug errors
- Lets you work step by step through the assignment
This is the expected workflow for completing labs in this course.
1.6.5 Why We Use R Notebooks in This Course
Using R Notebooks allows you to:
- Clearly connect analysis and interpretation
- Practice writing professional, data-driven explanations
- Keep your work organized and reproducible
- Learn workflows used in real analytics jobs
It also allows your instructor to:
- See both your code and reasoning
- Verify results
- Provide more meaningful feedback
1.7 Getting help when you’re stuck
These are the most useful help tools in R:
?function_nameopens help for a functionhelp.search("keyword")searches help files- If an error happens, read the last line carefully (it often tells you what to fix)
Examples:
1.8 How you’ll use this book
Most weeks, your workflow will look like this:
- Read the relevant sections of the book
- Open the lab file for the week
- Run the example code
- Modify the code to answer lab questions
- Interpret results and write conclusions
Errors are normal—debugging is part of learning analytics.