this ⟵ R project
A guest asks where the bathroom is, so you say:
"Go to the kitchen / turn left down the hallway / first door on the right"
Easy enough. Now imagine going to someone else’s house and offering the exact same directions.
Now you know what’s wrong with absolute file paths.
This appears at the top of Blake’s R script:
which is fine for Blake, but who works alone in science?
Imagine trying to cook dinner in a CDC lab…
That’s EXACTLY what it’s like working on multiple research projects in the same programming work-space.
Seriously, don’t do it.
A typical project folder might look like this:
If you open this in the RStudio IDE, the working directory will automatically be set to “root/path/to/my-r-project”.
Need to distinguish the essentials from the inessentials!
x is product iff x can run without error
head(cars) mean(cars$dist) + 1 # don't forget to do your laundry! <- sample(1:nrow(cars), size = 25, replace = FALSE) i <- cars[i, ] cars2 plot(cars2) Sys.Date() <- lm(dist ~ speed, data = cars2) bb8 summary(bb8)
But all this will 🏃🏃🏃…
x is product iff the goal requires x ✔
But teleology means it just depends… 🤷
consider what details you’d include when giving directions
your code is like that, but from your raw data to your results
“Wyman’s overpopulated universe is in many ways unlovely. It offends the aesthetic sense of us who have a taste for desert landscapes, but this is not the worst of it. Wyman’s slum of possibles is a breeding ground for disorderly elements.”
On What There Is (1948)
Translation: trust your R script! and be ruthless with your use of
here() finds the path to the project folder, though RStudio will do this, too…
library(here) # on blake's computer here() #>  "C:/Users/blake/rstuff/our-r-project" # on bob's computer here() #>  "C:/Users/bob/likes/subfolders/our-r-project" # on simon's computer here() #>  "?????/our-r-project"
here(), however, will also reference the top project directory no matter where you are in the project.
library(here) # on blake's computer, in the R folder here("data", "elevation.tiff") #>  "C:/Users/blake/rstuff/our-r-project/data/elevation.tiff" # on bob's computer, in the figures folder here("data", "elevation.tiff") #>  "C:/Users/bob/likes/subfolders/our-r-project/data/elevation.tiff" # on simon's computer, in the _misc folder here("data", "elevation.tiff") #>  "?????/our-r-project/data/elevation.tiff"
etc., etc., etc.
and we haven’t even gotten to drafts of our R scripts! hmmm… 🤔
Once you have git and Github setup, RStudio makes version control super super easy.
See happy git with r for details.
“but I want to share data across projects,” you will inevitably find yourself saying
and now you’re on the cutting edge 🔪🔪🔪
“The pins package publishes data, models, and other R objects, making it easy to share them across projects and with your colleagues.”
- From the package website
This looks promising, but I don’t have much experience with it. Need buy in from the collabs on using projects first…
let’s make an R project!