Lecture 17
Cornell University
INFO 5001 - Fall 2024
October 25, 2023
Don’t fret over past mistakes.
Raise the bar for new work.
self-explaining >>>
wordy, needy explainers
>>>
file salad
+ an out of date README
PLOS Computational Biology
Wilson, Bryan, Cranston, Kitzes, Nederbragt, Teal (2017)
work on more than 1 thing at a time
collaborate, communicate, distribute
start and stop
dedicated directory
RStudio Project
Git repo, probably syncing to a remote
Jenny will come into your your office and SET YOUR COMPUTER ON FIRE 🔥.
Project-oriented workflow designs this away. 🙌
rm(list = ls())
?Option | Persists? |
---|---|
A. library(dplyr) |
|
B. summary <- head |
|
C. options(stringsAsFactors = FALSE) |
|
D. Sys.setenv(LANGUAGE = "fr") |
|
E. x <- 1:5 |
|
F. attach(iris) |
01:00
RStudio leaves notes to itself in foo.Rproj
Open Project = dedicated instance of RStudio
dedicated R process
file browser pointed at Project directory
working directory set to Project directory
OR
Tools -> Global Options
Session -> Restart R
Windows
Mac
Cmd + Shift + 0
Cmd + Shift + F10
usethis::create_project("~/i_am_new")
File -> New Project -> New Directory -> New Project
usethis::create_project("~/i_exist")
File -> New Project -> Existing Directory
A large-scale study on research code quality and execution.
Trisovic, A., Lau, M.K., Pasquier, T. et al.
Sci Data 9, 60 (2022).
Working directory \(\neq\) home directory
Relative to a stable base, use file system functions
fs
= file path handling
Project directory
Automatically complete paths with Tab
.
Don’t hard-wire them into your scripts.
Instead, form at runtime relative to a stable base
Use the here
package to build paths inside a project.
Leave working directory at top-level at all times, during development.
Absolute paths are formed at runtime.
Artwork by @allison_horst.
Works on my machine, works on yours!
Works even if working directory is in a sub-folder.
Works for RStudio Projects, Git repos, R packages, etc.
Works with knitr / Quarto.
here::here()
The here
package is designed to work inside a project, where that could mean:
RStudio Project
Git repo
R package
Folder with a file named .here
here::here()
does not create directories; that’s your job.
Absolute path.
Relative path to working directory, established by the RStudio Project.
Are you sure it can’t?
Review the Good Enough Practices paper for tips.
Create a symbolic link to access the data. (fs::link_create()
, fs::link_path()
)
Put the data in an R package.
Use pins.
Explore other data warehousing options.
smell-test.R
wrangle.R
model.R
make-figs.R
report.Qmd
>>>
everything.R
raw-data.xlsx
data.csv
fit.rds
ests.csv
>>>
.Rdata
ae-15
ae-15
(repo name will be suffixed with your GitHub name).