Skip to content

Instantly share code, notes, and snippets.

@sergiouribe
Last active January 10, 2025 07:21
Show Gist options
  • Save sergiouribe/d01b4a11c44905f2232ce93c539bdd7a to your computer and use it in GitHub Desktop.
Save sergiouribe/d01b4a11c44905f2232ce93c539bdd7a to your computer and use it in GitHub Desktop.
Code Reproducibility Good Practices

R Code Reproducibility Good Practices

Minimal Rules

  1. Organize Your R Analysis Using Projects in Rstudio
    • Ensure at least three folders exist: code, data, and figures.
    • Tip: use analysistemplates package

      remotes::install_github("jonas-hag/analysistemplates")

  2. Use {here} and Avoid setwd
    • Never use setwd, ever.
  3. Divide Analysis into Specific Scripts
    • Use at least 01_data_acquisition_cleaning and 02_exploratory_data_analysis. Create additional scripts for modeling as needed.
  4. Store Data Frames as RDS in data Folder
    • The output of file 01 should be a data frame, preferably stored as an RDS for retaining order and metadata. If no relevant metadata/ordered levels are in the dataframe, a csv file will suffice.
  5. Maintain a Clutter-Free Environment Tab
    • Promptly remove unnecessary objects.
  6. Include Package References at the Beginning
    • Use package::function syntax for specific function calls.
  7. Comment Everything and Everywhere
    • Never assume you will remember your reasoning or logic in the future.
  8. Adhere to the Google R Style Guide
    • Regularly apply Control+Shift+A for automatic formatting.

Reference materials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment