|
Research Ideas and Outcomes :
Guidelines
|
|
Corresponding author: Pieter Huybrechts ([email protected])
Received: 24 Sep 2026 | Published: 19 Oct 2026
© 2026 Pieter Huybrechts, Ward Langeraert, Peter Desmet
This is an open access article distributed under the terms of the Creative Commons Attribution License (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
Citation:
Huybrechts P, Langeraert W, Desmet P (2026) B-Cubed software development guide. Research Ideas and Outcomes 12: e216899. https://doi.org/10.3897/rio.12.e216899
|
|
This guide specifies high-level requirements for software, computational tools and resources developed for B-Cubed (referred to in the sections as “software”) to ensure that the produced software meets the intended quality, openness, portability and reusability.
data cubes, FAIR software, software quality standards, open software, software metadata, interoperability, b-cubed, software versioning, software testing
These requirements*
The sections include requirements, as well as hands-on instructions and examples. They cover topics such as code repositories and collaboration, and in-depth development best practices, including testing and documentation, for both the R programming language. At the head of every section an overview is offered ²that summarizes the minimal requirements (MUST). The text of the section can include additional recommendations (SHOULD or RECOMMENDED).
The key words MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL in this document are to be interpreted as described in RFC 2119 (
All software code MUST be maintained on GitHub or GitLab. Code is maintained in a repository, which contains all files, discussions and version history related to a single software package or analysis.
.gitignore file.LICENSE file and be licenced under the MIT licence.README.md file.CITATION.cff file.You first need to define the scope of your repository. An installable software tool (R package, Python library, etc.) MUST be maintained in its own repository. For an analysis, choose a scope that is easy to manage and collaborate on.
It is RECOMMENDED that you start your repository before you write code. That way, you can follow best practices, others can contribute and all version history is captured from the start.
The easiest way to create a repository is in your browser:
.gitignore template (e.g. R, Python)If you already have your code (locally), follow About adding existing source code to GitHub. Using GitHub Desktop is the easiest option.
If your code is already on GitHub under a personal account, it MUST be transferred to the b-cubed-eu organization or your institution, if it has a well-established track record of maintaining code on GitHub. Contact the GitHub B-Cubed admin to gain the rights to transfer your repository to the b-cubed-eu organization.
Once you have created a repository, you SHOULD complete a number of additional steps.
LICENSE file.Mac operating systems create .DS_Store files to store attributes of a directory. These can clutter your repository and should be ignored.
Go to the .gitignore file.
Click the pencil icon.
Scroll to the bottom and add the following code (before the empty line): # Mac OS .DS_Store
Commit the changes.
Repositories MUST contain a CITATION.cff file so users know how to cite the software. Its metadata also gets picked up when depositing a repository to Zenodo (see releases. For more information see What is a CITATION.cff file or GitHub’s About CITATION files.
CITATION.cff.Note: this file can be updated later (manually or through functions).
Note: a CITATION.cff is different from the R-specific CITATION file (without an extension).
See the README file sections.
See the Code collaboration section.
A README file communicates the most important information about your repository/software. It will serve as a welcome sign for users, meaning that it will be the first and maybe most important piece of metadata that users will encounter. It often also serves as the landing page for a documentation website.
Maintainers SHOULD extend a README beyond its initial template when it was created as soon as possible, as it helps to define scope and expectations and facilitates collaboration. General guidance on writing a README can be found in GitHub’s About READMEs or Make a README, while software languages (e.g. Python or R) often have specific instructions. Some suggestions for its contents are detailed in the sections below. See the README.md of the frictionless package (
The README file MUST be written in Markdown (and therefore be named README.md), unless the software language recommends otherwise. Python for example recommends structured text (
A README MUST start with an H1 title with the (human-readable) name of the repository/software. The title is generally the same as the name of the package, see Naming your package.
Right below the title you can optionally show badges or shields to convey the current development status, link to a publication or archive, test coverage and more. Many GitHub workflows come with a status badge and static shields can easily be created using https://shields.io/badges. Vincent A. Cicirello provides a general overview in this blog post (
Maintainers SHOULD at least include a repo status or lifecycle badge, to indicate the maturity/support for the repository/software. See repostatus.org for statuses or lifecycle
Below the Title and the optional badges, a brief, title-less introduction MUST be provided, explaining the rationale and/or scope of the repository/software. A software package might initially limit its scope to only part of a bigger problem, and signal this in its description. For example, a package wrapping an API might only support reading from that API, not writing to it. Or an analysis library might only initially offer statistical functionality, but not any visualization of results.
While it can be very clear how to install a software package for those who were closely involved in writing them, the same is not always true for external users. Thus minimal instructions SHOULD be included in the README on how to install the software and its dependencies.
Similar to the installation instructions at least one example of the functionality of the analysis workflow or software SHOULD be included in the README.
A repository can have additional README files beyond the one in the root. These typically serve as an introduction to a specific directory. These SHOULD NOT be used, as there are better ways to document code, but it can serve as a quick way to describe data files. See this guide by Cornell University Data Services or Dryad’s best practices document for guidance. Better yet is to deposit your data elsewhere.
Open source software relies on collaboration. Participants in this process are not only developers, but anyone interacting with the software (code), such as maintainers, contributors, testers, users reporting issues, etc. To facilitate the collaboration process, it is good to adopt a number of community standards and best practices (see below).
For more information on open source software collaboration, see Finding ways to contribute to open source on GitHub (also useful for non-developers) and GitHub’s Open source guides. See how well your repository is adopting community standards at https://github.com/b-cubed-eu/<your-repo>/community.
A code of conduct is a document that establishes expectations for behaviour from all software participants. Adopting and enforcing it can help to create a safe and positive working space.
All software MUST have a code of conduct, as a CODE_OF_CONDUCT.md file following the Contributor Covenant template. All participants to software MUST abide by its code of conduct.
To add a CODE_OF_CONDUCT.md:
Alternatively, you can complete these steps in R using: usethis::use_tidy_coc()
But update the default email address ([email protected]) in “Enforcement” to [email protected] before committing the file.
Notifications are (email) alerts of participant activity in a repository or issue thread you are subscribed to. They facilitate collaboration and relieve you from having to check into GitHub.com. Activities that can trigger a notification include issues, pull requests and releases. Commits do not trigger a notification, which is why the GitHub flow (i.e. pull requests) is recommended to inform collaborators of important changes. You also won’t receive notifications for your own actions.
You are automatically subscribed to notifications based on your actions (like commenting on an issue) or the actions of others (like @mentioning or assigning you). You don’t need to be an official contributor to be notified; anyone can do so by clicking the Watch button on a repository homepage. Maintainers MUST watch the repository they maintain. If you receive too many notifications, you can control what events you want to be notified of.
When receiving a notification by email, click the view it on GitHub link at the bottom to interact. This generally provides better context and formatting options than your email client (see Report issues).
The GitHub flow is an easy-to-adopt practice for code collaboration that MUST be followed for all code contributions to B-Cubed software. It consists of making a branch, making changes, creating a pull request, addressing review comments, merging the pull request and deleting the branch. See GitHub flow for more information, including links to further documentation for all the steps.
The main branch MUST contain the software code in a state that can be installed without issue. To ensure code contributions (via pull requests) are reviewed before these are merged into the main branch, you can configure your repository to do so:
See also GitHub flow for working with branches.
Maintainers SHOULD clarify how participants can contribute to their software, by adding a contributing guide as a CONTRIBUTING.md file in the .github directory.
To add a CONTRIBUTING.md file:
Alternatively, you can complete these steps in R using: usethis::use_tidy_contributing()
Which will use the Contributing to tidyverse template.
While the GitHub flow lowers the barrier for making code contributions, it is useful (and saves you from writing unnecessary code) to interact with the maintainer(s) before suggesting changes. The easiest way to do so is by creating an issue.
Issues can be used to report and discuss a bug, idea or task. Issues are typically not used to ask for support in using the software. Anyone can create an issue or comment on it, and all participants watching the repository will get a notification. Once an issue is resolved (by fixing the bug, implementing the feature, or deciding not to act upon it) it can be closed. Closed issues are still accessible and can act as a history of decisions.
Writing a good issue takes skill, see this blog post (
Just like the README file, issues (and pull request) support Markdown formatting that can improve readability, link issues to code and other issues, and notify people. See the GitHub’s Basic formatting syntax guide for more information.
As a maintainer, you can nudge participants in the right direction by providing an issue template. Follow the Configuring issue templates for your repository instructions to do so. Alternatively, you can complete these steps in R using: usethis::use_tidy_issue_template()
But update or remove the references to https://stackoverflow.com or https://community.rstudio.com before committing the file.
While some contributions can be made directly in the browser (one file at a time), most software development will be done locally, in an environment where it can be run and tested. Git (and the GitHub flow) allow these changes to be synchronized. Rather than explaining how to use git, we recommend the use of GitHub Desktop to facilitate this process.
GitHub desktop is a visual interface that allows you to commit your changes (include file parts and multiple related files), push those to GitHub.com, pull changes from contributors, resolve merge conflicts, and switch branches. It works well next to other code editors such as R Studio. See the GitHub Desktop instructions to get started.
Code versioning (or version control) is an essential aspect of software development. It provides a mechanism to keep a detailed history of the changes that are made to the source code, as well as the decisions leading to those changes. This allows for a deeper understanding of the code and facilitates code audits/reviews. Code versioning also serves as a backup and recovery mechanism of the code. In case of critical errors or functionality loss, it is possible to revert to a previous working release of the software. Finally, versioning is an important communication mechanism for users of the software, especially software using it as a dependency. It indicates what changes can potentially break or alter existing functionality, offering the users the option to adapt their code or use a previous version.
Software MUST use semantic versioning, where the version number is of the form MAJOR.MINOR.PATCH. An example of version changes is presented in Table
| 0.1 |
First release |
| 0.2 |
Minor release |
| 0.2.1 |
Critical bug fix |
| 0.3 |
Minor release |
|
1.0-rc.1 |
Release candidate for version 1.0 |
| 1.0 |
First release of the public API (i.e. the collection of user facing functions) |
| 1.1 |
Minor release |
| 1.1.1 |
Critical bug fix |
| 1.2 |
Minor release |
There is no semantic difference between x.y.0 and x.y.
Versioning is built into git, where changes are expressed as commits. Try to create logical commits, where related changes are bundled together (and leave unrelated changes for a following commit). Document your commit with a concise commit message in the active tense (Add Pieter as contributor, Use 'invalid' over 'incorrect', etc.) and where necessary, document the reasoning in the commit description.
Major and minor versions MUST have an associated GitHub release:
Starting from release 1.0, authors MUST also publish their releases on Zenodo. Zenodo and GitHub are integrated, allowing this publication to be automated. See this tutorial (
By default, Zenodo will use the repository metadata to populate the deposit metadata. This will be of limited quality (e.g. GitHub usernames as author names). If a `CITATION.cff` file is present (see Add a CITATION.cff file, Zenodo will use that to populate the metadata. This will be of much higher quality, but you will typically have to review and update some properties manually on Zenodo, such as adding funding information, updating author affiliation to ROR-linked entries, updating the notes to the changelog and adding the deposit to the B-Cubed community.
See the b3doc R package (
If you prefer to fully automate the setup, you can add a .zenodo.json file in the root of the repository. In this file you can define Zenodo-specific metadata that will be used when a release is created. Note that for B-Cubed software, you must include the `b3` community and the `101059592` grant ID, otherwise the GitHub–Zenodo integration will silently fail:
{ "communities": [ { "identifier": "b3" } ], "grants": [ { "id": "101059592" } ]}
Further details on integrating GitHub and Zenodo using a .zenodo.json file are available in this tutorial (
Always verify the Zenodo record after the first release to ensure the integration behaves as expected.
The purpose of this section is to outline the requirements for software and scripts that are developed within the B-Cubed project. Data products are out-of-scope. However, many of the principles mentioned in this document can be applied to data products as well. For more details, we refer to the project deliverable D3.3 FAIR data products andinteroperability with the Essential Biodiversity Variables Data Portal (
To communicate and explain version changes, each repository SHOULD have a changelog. This changelog SHOULD be expressed as a NEWS.md file for R code (see the rOpenSci recommendations,
In R you can create a NEWS.md file using: usethis::use_news_md()
R is a programming language for statistical computing and data visualization.
R code is run in a specific context, with an associated working directory, history, etc. If that context is undefined or too broad, it can create conflicts between projects or make it hard for others to run your code.
To solve this, software MUST make the context explicit by including an RStudio project file (file with .Rproj extension) in the root of the repository to make the context explicit. This file will set your and everyone’s working directory at the root of the repository. In addition, software MUST only use relative paths starting at that project root to refer to files and MUST NOT use absolute paths. The implications of using absolute paths are described in the British Ecological Society guide on reproducible code (
Further benefits of RStudio Projects are described in this section of the R Packages book (
Please refer to the rOpenSci recommendations (
Some recommendations for common use cases:
In general, it is recommended to use packages from the tidyverse over base R functions in cases where the tidyverse alternative has significant advantages. For example, the case of readr::read_csv() over base::read.table(). The readr (
Adding a dependency to your DESCRIPTION file is easy using usethis: usethis::use_package("dplyr")
Refer to the rOpenSci recommendations for more suggestions.
Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread. --- R for Data Science
A number of useful packages exist to help you stick to the tidyverse style. To automatically modify your code to adhere to the recommendations, you can make use of styler (
Have you ever written any code that turned out to not really do what you wanted it to do? Made a change to a helper function that introduced bugs in other functions or scripts using it? Or found yourself running the same little ad hoc tests in the console time and time again to see if a function is behaving as expected? These are all signs that you could benefit from using automated testing.
By writing tests that check the major functionality of your software, you are ensuring that changes along the line don’t break existing functionality. And that updates to underlying dependencies didn’t have unexpected consequences.
A general overview of the how and why of testing R code is found in R Packages book chapter testing basics (
Start using testthat for an existing R project by running: usethis::use_testthat()
Which will create tests/testthat/ and tests/testthat.R, and adds the testthat package to the Suggests field.
Creating a test for an existing function is automated via usethis:
# Explicitly refer to the file we want to test
usethis::use_test("filename_to_test")
# Or automatically if the file is already open and active in Rstudio
usethis::use_test()
While it is a good idea to regularly run your tests locally, it is also a good idea to automate this in the form of continuous integration:
# Runs R CMD CHECK which includes running all test
usethis::use_github_action("check-standard")
# Calculate the code coverage and report
usethis::use_github_action("test-coverage")
You can also add badges to your README page to signal your R CMD CHECK status (which includes your unit tests) and test coverage:
usethis::use_github_action("check-standard", badge = TRUE)
usethis::use_github_action("test-coverage", badge = TRUE)
Tests can then be run by:
# For a package
devtools::test()
# Or else, make sure your functions are loaded and then
testthat::test_dir("tests/testthat")
The goal of unit testing is to compare the output of a function to some expectation or expected value, however, for some outputs this isn’t very practical. One example is binary outputs such as figures or plots. While testthat offers a solution for this in the form of snapshots (and this is certainly a very powerful and useful feature), these snapshot tests are very sensitive to minute changes.
vdiffr (
A final option is to use a public accessor of your plotting library, for example ggplot2 (
There are several packages to check how well your R code is following best practices (from which many of the requirements in this document are derived):
There are a number of advantages to wrapping existing code into functions, as put by
I don’t think I can overstate this, but learning how to write functions changed how I think about code and how I think about solving problems. --- Nicholas Tierney
This same blog post also contains a simple example of how to turn existing code into a function. A more in depth description can be found in the section on functions in R for Data Science (
To summarize the why, you should use functions to:
However, using functions is not without its pitfalls. But many issues can be avoided by sticking to some ground rules:
Functions need to be self-contained, the reasoning behind is explained well in the section “writing functions” in the British Ecological Society guide on reproducible code (
write_csv() from readr (Keeping your functions separate from analysis code can improve the readability of the analysis, and ease the maintenance of the functions. It is considered best practice to place every function in its own .R file, and to name this file after the function. As described in the R Packages book (usethis::use_r("function-name")
And start your function using the included code snippet in RStudio.
A sure way to confuse users is for a function to return a different output with the same inputs/arguments; this is the case when some of the inputs are implicit. For example, an option or locale setting, the system time or a local datafile that might have changed. Using implicit arguments can lead to difficult to trace behaviours across different computers, and makes a function more difficult to read. A notable exception is when there is an element of randomisation in the output. In this case it is a good idea to allow for setting the seed as a function argument to make this behaviour clear for the user and to allow for reproducible results. For more information about this, read this excellent section in the tidyverse design principles (
One of the best ways to improve your reach as a data scientist is to write functions. --- R for Data Science
Further reading:
The process of taking an existing script and converting it into a collection of functions that make the workflow more flexible, easier to maintain and more efficient, is an example of code refactoring.
An often repeated principle in refactoring and software development in general is DRY (Don’t Repeat Yourself), and while there are certainly situations (
Looking at an existing script, it is useful to consider what every part actually does (rubber duck debugging can be a useful technique in this). These logical sections and their substeps are good starting points.
Encapsulate repeated code blocks, or logical subsections that perform a single task (especially if they do it multiple times) into functions, and place objects that can influence the output as arguments. This can be a bit of a judgement call, but things like input file paths, output file paths, filters on the data such as taxonomy or time, number of bootstraps, random seeds etc. make for ideal argument choices. Often an object keeps being passed from section to section undergoing transformations on the way, and finally resulting in some output. If this is the case, the data object MUST be the first argument. For more guidance on this step, refer to the section on arguments.
The Research Institute for Nature and Forest (INBO) has a coding club session (
From the tidyverse style guide:
There are only two hard things in Computer Science: cache invalidation and naming things. --- Phil Karlton
Use verbs to name functions whenever possible, this is a clear indication that a function does something, in contrast to other objects. For more guidance please refer to the tidyverse style guide section on functions (
If you find this difficult, consider if your function isn’t doing too much. Ideally a function should only do one thing, and only return one thing.
Consistent naming of arguments across functions greatly improves user friendliness. For guidance on object naming, please refer to this section of the tidyverse style guide (
In the same vein, it is best practice to place the most important arguments first, because these will be used first. This practice is covered by the tidyverse design principles (
Similarly, functions that return objects or data of the same type as their input, MUST place this input as their first argument. This also ensures that functions are as compatible with pipes as possible (in base R |> or
Other tidyverse design principles regarding function arguments:
Functions that are well written can be considered partially self documenting, their name is an indication of what they do and their arguments tell the user what is expected and in what shape. However, apart from this, adding additional information will make it much easier for your future self and others to reuse your code. R comes with this functionality built in in the form of .Rd files in the man/ folder. Instead of creating these files manually, this additional documentation MUST be written in the form of roxygen2 (.Rd files are then rendered whenever you run: devtools::document()
It is recommended that you add at least one example of the basic functionality of your function in the roxygen2 documentation. A very minimal example that uses roxygen2 documentation is the fct_rev() function from forcats (
#' Reverse order of factor levels
#'
#' This is sometimes useful when plotting a factor.
#'
#' @param f A factor (or character vector).
#' @export
#' @examples
#' f <- factor(c("a", "b", "c"))
#' fct_rev(f)
fct_rev <- function(f) {
f <- check_factor(f)
lvls_reorder(f, rev(lvls_seq(f)))
}
An additional advantage of this system is that every function will automatically get its own page on your documentation website. A screenshot of the webpage that was created for the function above is shown in Fig.
Screenshot of the online documentation of the forcats function fct_rev() (licensed under MIT,
If you are new to documenting functions, have a look at the chapter on function documentation in the R Packages book (
Hadley Wickham and Jennifer Bryan have written an excellent guide on R Packages (
A lot of the tooling around R packages is also useful for R analysis code formatted as a script. However, while it might look intimidating at first, authoring an R package isn’t nearly as difficult as it might seem. Below there is an included example of R commands that set up an R package, and the required documentation, create a first function, tests for that function, update the documentation and run the package tests. All of this can be done equally well for a script, but this requires a lot more manual work.
# Starting a minimal R package --------
## Setup everything we need in a single line, isn't usethis amazing?
usethis::create_package("packagename")
## We will be using GIT for our version control
usethis::use_git()
# Further repository setup according to guidelines --------
## Add an MIT licence file
usethis::use_mit_license(copyright_holder = "institution name")
## Tell the world how to contribute
usethis::use_tidy_coc()
usethis::use_tidy_contributing()
## Write a README, in Rmd format if we want to show off our code
usethis::use_readme_rmd()
## Let's use github actions for some automation
usethis::use_github_action("check-standard", badge = TRUE)
usethis::use_github_action("test-coverage", badge = TRUE)
# Let's write our first function --------
usethis::use_r("cool_function_name")
## And add a test for it too!
usethis::use_testthat()
usethis::use_test()
## Update the documentation
devtools::document()
## Run all the tests
devtools::test()
Naming a package or analysis script can be difficult.
available::available("mycoolpkgname")
The CodeMeta project defines a codemeta.json metadata file (in JSON-LD format) that helps machines interpret information about your package. This is useful because it can ease the attribution, discoverability and reuse of your code beyond the tools already present in the R ecosystem. A codemeta.json makes it more likely someone will find your software who doesn’t know where to look for it, and that you’ll get credit for it when it is reused by allowing different metadata standards to be translated into each other via codemeta. The CodeMeta project makes a strong case for its inclusion in repositories. And so does rOpenSci (
Creating such a file is also very easy as it can be generated from the information already present in your README, DESCRIPTION and CITATION files. From the root of your package run: codemetar::write_codemeta()
Sometimes a package needs to communicate directly with its user; this is usually done through either message(), warning() or stop(). The rOpenSci Packages guide (print() or cat() because these kinds of messages are much more difficult for the user to suppress. Additionally, these kinds of messages are also more difficult to write good tests for.
Apart from base R, the package cli (stopifnot() from base. Please refer to the documentation of cli_abort() here. A practical example of how you could use cli instead of assertthat can be observed in this commit on the frictionless R package (
For general instructions, see the README file section. The README file for R packages largely takes the same form as the one required for all repositories. Additionally, a number of useful tools are available to you as a developer to create a great README.
If you don’t have a README yet, you can create one with usethis: usethis::use_readme_md()
If you want to include code and its output in your README, you can instead create a README.Rmd in R markdown, and then render that to a traditional README.md file. Again, you can create one with usethis: usethis::use_readme_rmd()
This will not only create a README.Rmd, but also add some lines to .Rbuildignore and create a Git pre-commit hook to help remind you to keep README.Rmd and README.md synchronized. After you’ve made changes to README.Rmd, remember to update README.md by running: devtools::build_readme() via the devtools package (
Usethis (README file, for example for the lifecycle (usethis::use_lifecycle_badge(stage = "stable")
Some other functions within usethis (README, for example you can advertize your code coverage using the test-coverage action: usethis::use_github_action("test-coverage", badge = TRUE)
A documentation website allows (potential) users to learn about your package and its functionality without having to install it first. Luckily, prior knowledge of web development is not needed to create a documentation website for R packages. It can be generated automatically with pkgdown (
# Run once to configure package to use pkgdown
usethis::use_pkgdown()
# Run to build the website
pkgdown::build_site()
By default, your website will include a homepage and a function reference, but there are several more pages you can add. The most useful ones are articles (called “vignettes”) to explain a certain functionality or workflow in a more tutorial-like fashion:
# Create a vignette
usethis::use_vignette("vignette-title")
Since vignettes are included in the source code; users can also consult them when offline (in RStudio):
# Loading a vignette from dplyr (works offline too)
library(dplyr)
vignette("in-packages")
# This is the same page as https://dplyr.tidyverse.org/articles/in-packages.html
Since we are using GitHub to host our code, deploying a website is fairly straightforward:
usethis::use_pkgdown_github_pages()
Neal Richardson posted a step-by-step guide to using pkgdown on his website (
The DESCRIPTION file includes, among others things, a list of all authors and contributors to the package. Apart from information about the authors, it also includes vital metadata about the version, licence and purpose of the included code. This file thus forms an important piece of metadata for the code it describes. This is also another place to refer to any external resources, such as the github repository where users can file bug reports or URLs to any external web APIs that may be called.
To uniquely identify the contributors to the software, it is very useful to include ORCID identifiers under the Authors in the description. The benefits of this are described on this rOpenSci blog post (
Authors@R: person( "Pieter", "Huybrechts", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6658-6062"))
Further guidance on editing DESCRIPTION files can be found in the chapter on package metadata in the R Packages book (
R packages commonly include a CITATION file (no extension) that provides information about how the package should be cited. See the CITATION file section in the rOpenSci Packages guide for guidance. This file can be created with:
usethis::use_citation()
And users can retrieve its information with:
citation("package-name")
All repositories MUST also include a CITATION.cff file (see Add a CITATION.cff file. You can keep it in sync with the CITATION file using a GitHub action provided by the cffr (
rOpenSci offers a useful blog post (
As described in the Create a repository section, all software produced in the context MUST be licenced under the MIT licence. The copyright holder of the software will be the institution that will be maintaining the package, not the authors of the package.
Adding this LICENSE file is easy with usethis,
usethis::use_mit_license(copyright_holder = "institution name")
This function will also set the License field in the DESCRIPTION file. For more information on package licensing, refer to the section on licensing in the R Packages book (
Examples show users how to use your software, and will often be the first thing people look at when they have trouble reusing your code. Thus including them not only fills an educational niche, but also provides a nice piece of documentation.
All functions intended to be used by users (i.e. public functions) MUST have an example in their roxygen2 (
Creating a vignette is automated by usethis (
usethis::use_vignette("vignette-title")
Dependencies are other packages your package relies on. Those need to be defined in the DESCRIPTION file, so that they are automatically installed when a user instals your package. You can use usethis (
usethis::use_package("package-to-depend-on")
This will add a package to the Imports section of the DESCRIPTION file. The function also allows you to set it to Suggests instead, or to declare a minimum package version. Declaring a minimum version of a dependency isn’t usually necessary and should only be done as a continuous choice. For more guidance on the tradeoffs and decisions around dependencies, read the section on package dependencies in the rOpenSci Packages guide (
The difference between Imports and Depends is that while both are installed together with the package, Depends are also attached to the global environment, thus opening the door to all kinds of trouble. For example, if your package Depends on dplyr (filter() which is loaded by default, because dplyr includes a filter() of its own. This kind of namespace conflict should be handled with caution, and avoided whenever possible. Code written by the user should behave as they expect, regardless of the order in which they load packages. Dependencies declared in Imports are not attached, thus avoiding this problem entirely. This principle and several other good practices are described in the section on package dependencies in the rOpenSci Packages guide (
When calling a function from a dependency, the dependency MUST be explicitly mentioned using package::function(). This makes it easier for collaborators to understand your code and it helps when searching for functions of a specific dependency:
# Bad
my_function <- function(file) {read_csv(file)}
# Good
my_function <- function(file) {readr::read_csv(file)}
For dependency recommendations, see the dependencies section in the R section.
An important note is that most R analysis scripts could be wrapped as a package. This has many advantages:
Creating an R package might seem like a huge step if you haven’t done it before, and while there is a learning curve, it really isn’t nearly as hard as it seems. All of this to say, please don’t be afraid to start an R package instead of an analysis script as part of your analysis workflow.
For more information on packages, refer to the R packages section.
An R analysis script/project can be started from scratch via usethis (
usethis::create_project("myprojectname")
This automates a number of steps:
.Rproj file..Rproj.user to .gitignore.As a next step you could initiate git:
usethis::use_git()
We would like to thank the following people for their valuable insights, feedback and discussion in relation to this publication: Damiano Oldoni, Floris Vanderhaeghe, Laura Abraham, Maarten Trekels, Maëlle Salmon and Thierry Onkelinx.
This work was supported by the B3 (Biodiversity Building Blocks for policy) project, which has received funding from the European Union's Horizon Europe Research and Innovation Programme under Grant Agreement No. 101059592.Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Executive Agency. Neither the European Union nor the granting authority can be held responsible for them.
This guide was first created as B-Cubed project deliverable D3.1 Quality requirements for software (