Week 1: File Management Practice
MKT 378 — Marketing Research & Analytics
Overview
Goals for this assignment:
- Download and install R and RStudio
- Open and run an R script
- Familiarize yourself with file management on your personal computer
- Practice a clean folder setup
- Save a CSV to a
/Datasetsfolder - Load it back using a relative path in R/RStudio
A relative path tells R where to find a file relative to your current working directory—like saying “go into the Datasets folder from here.” An absolute path spells out the entire route from the root of your computer, like /Users/erin.p.carter/Documents/Marketing_Research/Datasets/file.csv. Relative paths are shorter, portable, and won’t break when you move your project folder or switch computers.
Part 1: Set Up Your Class Folders
Before we touch R, let’s get your computer organized. Create a main class folder somewhere you control—your Desktop or Documents folder works well.
Name it something like:
Marketing_Research_R_Fall2025
The exact names don’t matter for the code to work—you could call your folder dinofartbroccolini and save your scripts as various Kings of England if you want. You just need to know where things are stored so you can find them later.
That said, I’d recommend a nice, safe, boring file structure. Inside your main folder, create subfolders like:
Marketing_Research_R_Fall2025/
├── Code/
├── Datasets/
├── Homework/
└── Resources/
Do NOT work from your Downloads folder. Files there get buried and accidentally deleted.
Be careful with cloud-only locations (Google Drive, iCloud, OneDrive) unless the folder is fully synced to your local machine. Cloud sync can cause weird errors when R tries to read or write files that are still uploading.
Part 2: Install R and RStudio
You only need to do this once.
Step 1: Install R
Go to https://cran.r-project.org
- Choose your operating system (Mac, Windows, or Linux)
- Download and run the installer
- Accept the defaults
Step 2: Install RStudio
Go to https://posit.co/download/rstudio-desktop/
- Download the free RStudio Desktop version
- Run the installer
- Accept the defaults
Step 3: Open RStudio
Open RStudio (not R directly—RStudio is the friendlier interface that runs R for you).
To create a new script file:
- Go to File → New File → R Script
- If that’s grayed out, use the toolbar icon (white page with a green “+”) or press
Ctrl+Shift+N(Windows) /Cmd+Shift+N(Mac)
Part 3: Create an RStudio Project
An RStudio Project ties your work to a specific folder. When you open the Project, R automatically knows where your files are. This is the key to making relative paths work.
- In RStudio: File → New Project
- Choose Existing Directory
- Navigate to your
Marketing_Research_R_Fall2025folder and select it - Click Create Project
Now, whenever you open this Project, your working directory will automatically be set to your class folder.
Look for a file called Marketing_Research_R_Fall2025.Rproj in your class folder. Double-click it, and RStudio will open with everything configured.
Part 4: Create and Save Your First Script
Now let’s create a script file to store our code.
- In RStudio: File → New File → R Script (or click the white page icon with a green “+”)
- You should see a blank script panel in the top-left of RStudio
- Save this file to your Code folder:
- File → Save As
- Navigate to
Marketing_Research_R_Fall2025/Code/ - Name it something like
HW1_file_management_practice.R
A quick orientation to RStudio
RStudio has four main panels:
- Top-left (Source/Script): Where you write and edit code
- Bottom-left (Console): Where R actually runs your code and shows output
- Top-right (Environment): Shows what data and variables R currently has loaded
- Bottom-right (Files/Plots/Help): File browser, visualizations, and documentation
How to run code
To run a single line: Put your cursor on the line and press Cmd+Return (Mac) or Ctrl+Enter (Windows).
To run multiple lines: Highlight the lines you want and use the same keyboard shortcut, or click the Run button in the top-right of the script panel.
To run the entire script: Click Source or press Ctrl+Shift+Enter (Windows) / Cmd+Shift+Enter (Mac).
Part 5: Quick Check—Where Are We?
Let’s verify that R knows where we are. Run this command:
When you run this, your console (the pane below your script) should show something like:
[1] "/Users/yourname/Documents/Marketing_Research_R_Fall2025"
This is your working directory—the folder R considers “home base” for finding and saving files.
If the path shown is NOT your class folder, you probably didn’t open the RStudio Project. Close RStudio, find the .Rproj file in your class folder, and double-click it to open.
Alternatively, you can set the working directory manually with setwd(), but I recommend using Projects instead—it’s more reliable.
Part 6: Create a Dataset
Let’s make a small practice dataset. Imagine we’re tracking pop-up tastings for a “Maine Blueberry Beverage” across several towns. We recorded the town name, local advertising spend, foot traffic, and average satisfaction scores.
Run the following code:
# Create variables
Town <- c("Orono", "Bangor", "Portland", "Bar Harbor", "Lewiston", "Augusta")
AdSpend <- c(120, 180, 350, 220, 150, 160) # local ad dollars
FootTraffic <- c(85, 110, 240, 130, 95, 100) # people who stopped by
Satisfaction <- c(78, 80, 88, 85, 76, 79) # avg satisfaction (0-100)
# Combine into a data frame
maine_marketing <- data.frame(
Town, AdSpend, FootTraffic, Satisfaction,
stringsAsFactors = FALSE
)
# Display the data
print(maine_marketing)When you run this, you should see the data print in your console:
Town AdSpend FootTraffic Satisfaction
1 Orono 120 85 78
2 Bangor 180 110 80
3 Portland 350 240 88
4 Bar Harbor 220 130 85
5 Lewiston 150 95 76
6 Augusta 160 100 79
You should also see maine_marketing appear in your Environment panel (top-right) as a dataset with 6 observations and 4 variables.
Part 7: Save the Data to a CSV File
Now we’ll save this dataset to your Datasets folder using a relative path.
Because your working directory is already set to your class folder, you don’t need to type the full path. You can just say “go into the Datasets folder and save this file there.”
If you see something like cannot open the connection or No such file or directory, I’d bet a metaphorical $1,000,000 it’s because you don’t have a folder called Datasets in your working directory.
Fix: Either create a folder called Datasets in your class folder, or change the code to match whatever folder structure you actually have.
Verify the file was created
You can check manually by opening your Datasets folder in Finder/File Explorer. Or you can ask R to check for you:
If it returns TRUE, the file is there.
Part 8: Load the CSV Back into R
Now let’s practice loading data from a file—something you’ll do constantly in this class.
Run this code:
If you’ve been following exactly as written above, that should NOT have worked. You should have received an error message in your console.
Take a moment to figure out why before reading on.
Check the file name carefully. What did we name the file when we saved it?
We saved the file as maine_marketing_sample.csv, but we tried to load maine_marketing.csv. The names don’t match!
I tricked you a little there—but only with the best of intentions. This is the kind of error you will make approximately 1,000 times in your coding career. Noticing small differences in file names is a skill you’ll develop.
The correct code is:
Now run the corrected version and verify it worked by printing both datasets:
They should look identical.
Part 9: Verify the Data Matches
You confirmed with your eyes that the datasets look the same. But eyeballing data is inefficient—especially when datasets have thousands of rows. Let’s ask R to compare them for us.
OK, the code ran without errors… but nothing happened. R just sits there. What did we miss?
We told R to create something called same and store the result of all.equal() in it. But we never asked R to show us what same contains.
R is very good at a literal, nerdy version of “Simon Says.” We have to explicitly ask it to display things.
Try this:
You should have gotten an error: object 'Same' not found.
Well, this class is broken. The professor clearly doesn’t know what she’s doing. Here you are having to troubleshoot her broken code…
Actually, no. We defined same (lowercase), but we typed Same (capitalized). R is case-sensitive—same and Same are completely different things to R.
Try:
You should see [1] TRUE, confirming the datasets are identical.
In this case, the verification saved us zero time—the data was tiny and obvious. But when your datasets have thousands of rows, being able to programmatically verify things is invaluable.
Troubleshooting Checklist
If you see errors like cannot open the connection or no such file or directory, work through this checklist:
What folder is R actually in? Run
getwd()and verify it’s your class folder.Does R see your file? Try:
Check for typos. File names must match exactly, including capitalization and underscores.
Are you using forward slashes? In R, always use
/in file paths, even on Windows. (I know this is hard for you PC folks. Hang in there.)Did you open the RStudio Project? If you just opened RStudio without opening the Project file, your working directory might be somewhere else entirely.
Is the file open in another program? If you opened the CSV in Excel, close it and try again. Some programs lock files while they’re open.
Bonus: Save a Dated Backup
Here’s a handy trick for keeping track of different versions of your data: automatically add today’s date to the filename.
# Get today's date in YYYY-MM-DD format
today <- format(Sys.Date(), "%Y-%m-%d")
# Create a filename with the date
csv_dated <- file.path("Datasets", paste0("maine_marketing_", today, ".csv"))
# Save the file
write.csv(maine_marketing, csv_dated, row.names = FALSE)
# Check what's in your Datasets folder now
list.files("Datasets")You should see both your original file and a new dated version.
To load the dated file back:
This pattern is useful when you’re iterating on data cleaning or analysis and want to preserve earlier versions.
Submission
To complete this assignment:
- Make sure you can successfully run all the code in this document
- Take a screenshot showing your RStudio with:
- Your script in the top-left panel
- The
maine_marketingdata printed in the console - The Environment panel showing your loaded datasets
- Submit the screenshot to Brightspace
If you’re having trouble, check the Resources page for links to helpful documentation, or come to office hours. File management issues are extremely common at the start—you’re not alone!