Lecture 16
Cornell University
INFO 5001 - Fall 2024
October 24, 2024
Exam begins tomorrow at 8am
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
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
library()
Treat your source code as precious, not the workspace
Image credit: What They Forgot to Teach You About R
OR
Tools -> Global Options
Image credit: R for Data Science
Session -> Restart R
Windows
Mac
Cmd + Shift + 0
Cmd + Shift + F10
Write every script like its running in a fresh process
Best way to ensure this: write every script in a fresh process
write_rds()
& read_rds()
cache: true
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 run-time 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.
here::here()
data/
scotus.csv
analysis/
exploratory-analysis.qmd
final-report.qmd
scotus.Rproj
.qmd
and assumption of working directoryread_csv("data/scotus.csv")
read_csv(here("data/scotus.csv"))
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.
.Renviron
.Rprofile
.Renviron
usethis::edit_r_environ()
.Renviron
.Rprofile
.Renviron
.Rprofile
files
~/.Rprofile
).Rprofile
overrides home .Rprofile
usethis::edit_r_profile(scope = c("user", "project"))
.Rprofile
renv