Skip to main content
Researchdata.se

Scientific code

This page provides information about how to publish scientific code openly. It summarizes what to consider when writing code, how to prepare the code for publication, where to publish, how to choose a licence, and how to ensure that your code can be understood, reused, and cited.

Why publish scientific code openly?

Scientific code can be used for generating, cleaning, analyzing, or visualizing data. It can also implement models or workflows, or create software packages. Text files written in programming languages are known as source code; in programming languages like R and Python, source code files are sometimes referred to as scripts.

Open-source code is an important part of good research practice and contributes to transparency, reproducibility, and long-term preservation of research results. Code that was not originally developed with the intention of being openly published can still be valuable if it can be read and used by others. In other cases, the research explicitly aims to create open-source software that can be reused and modified by anyone.

Reasons for publishing code openly

  • Transparency: By making the code associated with research data available, you make it easier for others to understand how published data were processed and analyzed. It is part of good research practice.
  • Reproducibility: By publishing data, documentation, and code together, you enable others to recreate, verify, and build on scientific results.
  • Preservation: By publishing and archiving code in a good way, it is safely and securely preserved for the future, both for yourself and others.
  • Citation: You and others can refer to the code using persistent links and cite it in scientific publications.
  • Requirements from journals: You can meet the requirements or recommendations on open sharing of code and data from journals or funders.

Things to consider when publishing scientific code

Scientific code you publish needs to be understandable and reusable by others. It is therefore important to implement good code management. The most important aspects are summarized below.

Choose where to publish your code
Create a sensible file structure
Structure the code so that it is easy to understand
Describe the programming environment in which the code was created
Document your code and workflow
Show how your code can reproduce your results
Choose a licence that makes your source-code open
Test and review your code

Do you want to know more?

The information on this page is based on the following sources:

  • Barnes, N. (2010). Publish your computer code: it is good enough. Nature, 467(7317), 753. https://doi.org/10.1038/467753a LinkOpens in a new tab
  • Barker, M., Chue Hong, N. P., Katz, D. S. et al. (2022). Introducing the FAIR Principles for research software. Scientific Data, 9, 622. https://doi.org/10.1038/s41597-022-01710-x LinkOpens in a new tab
  • Ivimey-Cook, E. R., Pick, J. L., Bairos-Novak, K. R. et al. (2023). Implementing code review in the scientific workflow. Journal of Evolutionary Biology, 36(10), 1347–1356. https://doi.org/10.1111/jeb.14230 LinkOpens in a new tab
  • Katz, D. S., Chue Hong, N. P., Clark, T. et al. (2021). Recognizing the value of software: a software citation guide (v2). F1000Research, 9, 1257. https://doi.org/10.12688/f1000research.26932.2 LinkOpens in a new tab
  • Lee, B. D. (2018). Ten simple rules for documenting scientific software. PLOS Computational Biology, 14(12), e1006561. https://doi.org/10.1371/journal.pcbi.1006561 LinkOpens in a new tab
  • MIT Communication Lab (n.d.). Best Practices for Coding, Organization, and Documentation. https://mitcommlab.mit.edu/broad/commkit/best-practices-for-coding-organization-and-documentation LinkOpens in a new tab
  • R Core Team (2024). R: A language and environment for statistical computing. Vienna: R Foundation for Statistical Computing. https://www.r-project.org LinkOpens in a new tab
  • Trisovic, A., Lau, M. K., Pasquier, T. & Crosas, M. (2022). A large-scale study on research code quality and execution. Scientific Data, 9, 60. https://doi.org/10.1038/s41597-022-01143-6 LinkOpens in a new tab
  • University of California, Berkeley Library (2023). How to Write Good Documentation. https://guides.lib.berkeley.edu/how-to-write-good-documentation LinkOpens in a new tab