Workflow
Overview
Having a solid R workflow is incredibly important for efficient and reproducible data analysis. It involves key practices like using R projects, leveraging the {here}
package, and restarting the R session regularly. R projects provide a structured and isolated environment, ensuring project-specific settings and fostering collaboration. The {here}
package simplifies file path management, boosting code portability across different systems, and saving you from the headaches of dealing with setwd()
. Additionally, restarting the R session helps eliminate potential issues and ensures a clean workspace, reducing errors and allowing you to start fresh with your code execution.
Slides
Open the slides in a new tab here.
Exercises
- Create an R project for this workshop (you do want to check off “Use renv” – we’ll get to that later)
- Install the
{here}
package - Download the
.csv
file at https://raw.githubusercontent.com/louisahsmith/reproducible-epi-workshop-2023/main/data/nlsy.csv - Create a
data
folder within your R project directory and move thenlsy.csv
file there. - Run
here::here("data", "nlsy.csv")
and see what file path prints out. Compare with your neighbor. - Run
read.csv(here::here("data", "nlsy.csv"))
to make sure your can read in the file. - Restart the R session to start fresh!
Resources
- Jenny Bryan’s blog post: Project-oriented workflow
- Another blog post by Malcolm Barrett
{here}
package documentation: