15 Open Code

If research code is entirely secondary, it should be cited rather than shared directly (see Section 16). However, this is likely to be rare, and research code that is modified in any way from the original should be both cited and shared.

15.1 Tips

15.1.1 Make it reproducible

  • Include all the external files (e.g., data files) needed to run it
  • Use relative paths so that it can run on any computer
  • Set a seed if your code uses simulations or random number generation

15.1.2 Make it clear

  • Include a README that explains how to run the code
  • Assume that the audience has varying technical expertise and doesn't necessarily know the conventions of the language you're using
  • Indicate which parts of your code produce any figure, table, or value in your manuscript
    • Beginner: include comments in your code like # produces Figure 3.1
    • Intermediate: Use code the generate the text of the results section so you only have one thing to copy and paste into the manuscript
    • Advanced: Use code to generate the entire manuscript (e.g., using the papaja package)

15.1.3 Indicate software versions

  • Beginner: Include a text file with the info, e.g., devtools::session_info() in R, or requirements.txt in python
  • Intermediate: Or use dependency management, like renv or packrat in R
  • Advanced: Or use containers like Binder, Docker or CodeOcean for full reproducibility

15.1.4 Confirm reproducibility

  • Beginner: Access your shared materials from a new computer and run the code
  • Intermediate: Or ask a colleague to try running your code on their machine
  • Intermediate: Or set up more formal code review (Vable et al., 2021) in your group
  • Advanced: Or use a service like CodeCheck

NB: If your code takes a very long time to run, such as when you have extremely large datasets or are running simulations, you can include smaller test datasets or run a smaller number of replications and include code at the top of the script to toggle real and test data or low and high numbers of reps.

15.1.5 Share and license

  • Add a license so others know how they can use and modify the code. See Appendix B for more details.
  • Make your code findable using the same tips from Section 14.1.4
  • GitHub is a common place to share code, but doesn't create a DOI, so if you use github, consider archiving a snapshot of your repository on zenodo.