Project Management and Coding Best Practices

Objective

Learners will learn about and practice managing their projects using file structure and RStudio projects, and about current best practices and style guides for R coding.

Lesson Outline

  • Introductions
  • Discuss reproducibility
  • Give tour of course website & syllabus
    • Point out code of conduct
  • Screen setup
  • Don’t save or load .RData!
  • Discuss general best practices for research compendia (use Carpentry lesson)
    • All files needed for a project in the same folder (ideally)
    • Organize data, code, and outputs into different folders at a minimum
    • Never edit raw data
    • Include documentation on what each file is/does in a README
  • Live Coding: create an R project and add gapminder data to it
    • Show file pane & connect to Windows Explorer / Finder
    • Show how to make a file read-only
    • Demo closing, opening, and switching projects
  • Live Coding: R code best practices
    • Create 01-wrangle-data.R in R/
    • Header comment
    • Don’t use setwd()—not needed with .Rproj. Use relative paths!
    • Keyboard shortcut for adding sections + outline view and navigator at bottom of script panel
    • Load packages at top of script, even when not used until later
    • Restart R and run from top often
    • Code styling with RStudio (ctl + shift + A)
    • How to break up code (e.g. save output of 01-wrangle-data.R into data_clean/, then read that in later)
  • Homework:
    • Apply one or more of the organizing principles of a research compendium to an existing research project.

Installation & materials

  1. Slides
  2. Software Carpentry Introduction to R and RStudio episode
  3. Software Carpentry Project Management with RStudio episode
  4. Software Carpentry Best Practices for Writing R Code
  5. https://r4ds.hadley.nz/workflow-style

Citation

BibTeX citation:
@online{scott2023,
  author = {Scott, Eric and Diaz, Renata and Guo, Jessica and Riemer,
    Kristina},
  title = {Project {Management} and {Coding} {Best} {Practices}},
  date = {2023},
  url = {https://cct-datascience.github.io/repro-data-sci//lessons/1-project-management/notes.html},
  doi = {10.5281/zenodo.8411612},
  langid = {en}
}
For attribution, please cite this work as:
Scott, Eric, Renata Diaz, Jessica Guo, and Kristina Riemer. 2023. “Project Management and Coding Best Practices.” Reproducibility & Data Science in R. 2023. https://doi.org/10.5281/zenodo.8411612.