or, How to keep your computer safe from fire
There’s a famous blog post about workflows in R1 about a talk Jenny Bryan gave that included this slide:
If the first line of your R script is
I will come into your office and SET YOUR COMPUTER ON FIRE 🔥.
If the first line of your R script is
I will come into your office and SET YOUR COMPUTER ON FIRE 🔥.
From my first year of learning R:
…and there’s a good chance it has some of these bad habits.
Note
Unless you have given it a full project context (e.g., full directory permission with Claude Code), an AI has no idea what your file structure looks like and how everything should fit together.
Note
Posit, the company behind RStudio, has a new IDE called Positron that is designed to work with a project structure. The approach is slightly different than RStudio, but the principles are the same.
my-project/
├─ my-project.Rproj
├─ README.md
├─ data/
│ ├─ raw/
│ └─ processed/
├─ R/
├─ results/
│ ├─ tables/
│ ├─ figures/
│ └─ output/
└─ docs/
An .Rproj file is mostly just a placeholder text file that lives in your project folder
Otherwise your project acts just like any other folder on your computer
You can essentially turn any folder on your computer into an R project, or make a new one via RStudio when you create an R project
.Rproj fileYou can have multiple projects open at once in different RStudio sessions!
In the exercises, we are going to make some more changes to the repo you forked and cloned
.R script and a .csv file from the websiteepi590r-in-class repo in your file browserR folder and a data folderdata folder add a raw and a clean folder..csv file in the data/raw folder and the script in R folder.epi590r-in-class/
├─ epi590r-in-class.Rproj
├─ README.md
├─ R/
│ └─ clean-data-bad.R
├─ data/
│ ├─ raw/
│ │ └─ nlsy.csv
│ └─ clean/
Return to RStudio. If you closed RStudio, make sure you re-open this project. Look to the filepane to confirm the files are there.
Stage, commit, and push the changes you’ve made.
Try to run the code, line-by-line, in clean-data-bad.R.
epi590r-in-class.Rproj file in your file browser