This is an attempt to make an R project template, that is not an R package, and that uses some of the recent tools that have been created in the R ecosystem. The template is inspired by the python-project-template by Gemma Danks.
The project features rv for project management and packaging, jarl for linting, and air for formatting, justfile, testthat testing, quarto documentation created with quartrify, .editorconfig, .devcontainer, GitHub Actions CI, and automated semantic releases.
While the template can help you start writing code immediately without having to spend time deciding what tools or conventions to use, the tools and conventions that it introduces are not the default way of doing things in the R world, and there is a question mark if they get adopted in the future or not.
- π± Create a New Repository on GitHub
- Click "Use this template".
- Choose βCreate a new repositoryβ.
- Pick a name for your new project (for example,
my-awesome-package). - Clone your new repo locally
- π‘ Customise the repository
- Rename your package directory
cd src; mv package_name my_package - Update rproject.toml with your package name, author, and description, and preferred repository.
- Update all references to package_name in:
- src/package_name/__tests__/
- docs/
- release-please-config.json
- GitHub Actions workflow
- This README (including badge links)
- Update the
"package-name"field in release-please-config.json with your package name for automatically bumping the version number in rv.lock (see release-please issue #2561). - Customise this README with a description of your project and planned features.
- Clear the CHANGELOG.
- Enable automated releases by permitting GitHub Actions to open PRs (Settings -> Actions -> Workflow permissions) and add an initial commit hash to bootstrap the release-please in .release-please-manifest.json.
- Enable publishing to GitHub Pages (Settings -> Pages).
- Rename your package directory
- Modular project directory structure using box.
- README template with badges.
- Packaging and dependency management via rv: rproject.toml.
- Linting via Jarl.
- Formatting via Air.
- Testing framework using testthat.
- Git hooks via prek (linting and formatting).
- CI using GitHub Actions: .github/workflows/ci.yml.
- Docs generated with quartify and rendered as a single Quarto website, deployed to GitHub Pages via GitHub action: .github/workflows/generate-docs.yml.
- Templates for GitHub issues: bug report (01-bug.yml) and feature request (02-feature.yml).
- Template for GitHub pull request: .github/pull_request_template.md.
- Template for documenting architectural decisions: docs/architecture/adr/template.md.
- ADR to explain the rationale for using ADRs: docs/architecture/adr/001-use-architectural-decision-records.md.
- Release automation via GitHub action from release-please: release-please-config.json.
- Citation metadata, automatically updated for each new release: CITATION.cff.
- EditorConfig configuration for consistent coding style across editors: .editorconfig.
- Test coverage cannot be registered with codecov because it seems the R package
covrdoes not work in this type of project structure. pkgdowncannot be used for documentation for the same reason as above.devtools::check()does not work because it expects a package structure with aDESCRIPTIONfile and anR/directory for source code, which this template does not have.
A Dockerfile and configuration in .devcontainer can be used in VSCode or GitHub Codespaces to work in a pre-configured development environment. It uses an R base image and installs Quarto, rv, air, jarl, prek, and just.
To open the project in the container VSCode, you will need to add the Dev Containers extension and download Docker (or Podman -- and configure VSCode to use podman instead of Docker) -- see the VSCode tutorial on devcontainers for more details on using devcontainers. Then run:
Dev Containers: Reopen in Container- Install rv
- optional, if you want to use shortcut commands, install just
- optional, if you want to use pre-commit hooks, install prek
- optional, if you want to build the docs site locally, install Quarto
- Clone and install the project using rv:
git clone https://github.com/novica/r-project-template
cd r-project-template
rv sync- Install pre-commit hooks (only needs to be done once):
just pre-commit-install
Several common tasks have been added as recipes to a justfile in the root of the repository:
default # Default recipe (shown when running plain `just`)
install # Install dependencies (rv sync)
update # Upgrade packages to the latest versions available (rv upgrade)
lint # Lint (Jarl check)
format # Format (Air format)
test # Run testthat
docs-build # Build docs (Quartify generates reference qmd, Quarto renders the site)
pre-commit-install # Install git hooks (via prek)
pre-commit # Run all git hooks (via prek)- Generated with quartify and rendered as a single Quarto website (
just docs-build), combining this README, the architecture/ADR docs, and the generated API reference. See ADR-004.
Managed by release-please: (conventional commits drive semantic versioning and an autogenerated CHANGELOG). - Configuration: release-please-config.json - Version source: rproject.toml
.
βββ src/
β βββ package_name/ # Source package
β βββ __init__.r
β βββ hello.r # Example module (replace with real code)
| βββ __tests__/ # Test suite for the example module
| βββ __init__.r
| βββ helper-module.r
| βββ test_hello.R
βββ data-raw/ # Raw data used in the project (if applicable)
βββ docs/ # Documentation site (Quarto website, see ADR-004)
β βββ _quarto.yml # Hand-authored Quarto website project
β βββ index.qmd # Home page ({{< include ../README.md >}})
β βββ architecture/ # Hand-written: architecture overview + ADRs
β β βββ index.md
β β βββ adr/
β βββ reference/ # Generated by quartify (gitignored, rebuilt by `just docs-build`)
β βββ html/ # Rendered site output (gitignored; deployed to GitHub Pages)
βββ notebooks/ # Quarto notebooks
β βββ demo.qmd
βββ .github/
β βββ workflows/
β β βββ ci.yml # Lint / test / build
β β βββ generate-docs.yml # Generate and deploy docs
β β βββ release-please.yml # Automated releases
| | βββ update-citaton-date-released.yml # Update date-released in CITATION.cff on new release
βββ .devcontainer/ # Dev container configuration
β βββ devcontainer.json
β βββ Dockerfile
βββ rproject.toml # Project metadata + dependencies (rv)
βββ rv.lock # Locked dependency versions (rv)
βββ README.md # Project overview (you are here)
βββ CITATION.cff # Citation metadata
βββ LICENSE # License
βββ NEWS.md # Generated by release-please (post-release)
βββ .pre-commit-config.yaml # Git hooks configuration (run via prek)
βββ .release-please-manifest.json # Release-please state
βββ release-please-config.json # Release-please configuration
βββ justfile # justfile containing recipes for common tasks
βββ .editorconfig # Ensures consistent code style across editors
βββ .gitignoreNote that while it is common practice to keep the config files at the root of the
repository, and this is what I recommend, it is possible to customise the
location of some of them if you prefer
(e.g. the path to release-please-config.json [can be specified in the
release-please.yml file for the GitHub action]
(https://github.com/googleapis/release-please-action?tab=readme-ov-file#advanced-release-configuration).
Use conventional commit messages (feat:, fix:, docs:, etc.). Ensure:
- Lint & format clean
- Tests pass
- Docs build without warnings
- ADR drafted for architecturally significant changes
Suggestions and improvements to this template are very welcome β feel free to open an issue or pull request if you spot something that could be refined, added or removed.
If used in research, cite via CITATION.cff.
BSD-3-Clause β see LICENSE.
Happy coding! π