R project template
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 uvr for project/package management and R version installation, jarl for linting, air for formatting, ry for static type checking, justfile, testthat testing, a Quarto documentation site, .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.
How to use this template
- π± 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 uvr.toml with your package name, author, and description, and preferred repository.
- Update all references to package_name in:
- scripts/ (
run-tests.R,gen-rd.R) - docs/ (
_quarto.yml) - notebooks/demo.qmd
- release-please-config.json
- docs GitHub Actions workflow
- This README (including badge links)
- scripts/ (
- Update the
"package-name"field in release-please-config.json with your package name for automatically bumping the version number in uvr.toml (see release-please issue #2561). - Customise this README with a description of your project and planned features.
- Clear the
NEWS.md. - 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
π Features
- Modular project directory structure using box.
- README template with badges.
- Packaging, dependency management, and R version installation via uvr: uvr.toml.
- Linting via Jarl.
- Formatting via Air.
- Static type and scope checking via ry.
- Testing framework using testthat.
- Git hooks via prek (formatting, linting and static checking).
- Editor setup for VS Code / Positron: recommended extensions for air, jarl, ry and Quarto (.vscode/extensions.json), format on save (.vscode/settings.json).
- CI using GitHub Actions: .github/workflows/ci.yml.
- Docs generated with boxβs own roxygen parser + rd2qmd 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.
- Dependabot weekly updates for GitHub Actions: .github/dependabot.yml.
- 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.
βΌοΈ Limitations
- 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.rydoes not resolvebox::use()imports. Referencing a box-imported module or name (hello$say_hello(),lapply(x, say_hello)) reports a false RY010 (unbound variable), andbox::use(dplyr[filter])is treated asstats::filter. Suppress with# ry: ignore[RY010]or list the names underglobalsin ry.toml.
π¦ Installation
Working in a development container
A Dockerfile and configuration in .devcontainer can be used in VSCode or GitHub Codespaces to work in a pre-configured development environment. It uses a minimal Debian base image and installs Quarto, uvr (which then installs R itself), air, jarl, ry, prek, rd2qmd, 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 ContainerManual installation
- Install uvr
- Install air, jarl and ry (the git hooks run the installed binaries)
- 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 and rd2qmd
- Clone and install the project using uvr:
git clone https://github.com/novica/r-project-template
cd r-project-template
uvr r install $(cat .r-version)
uvr sync- Install pre-commit hooks (only needs to be done once):
just pre-commit-install
Day-to-day: is uvr how you run things?
No β uvr only installs R itself and syncs .uvr/library; .Rprofile then wires that library onto .libPaths() automatically. Once youβve run uvr sync, write and run code in src/package_name/ and notebooks/ from your normal R session (RStudio/Positron/terminal R, or quarto render) β no uvr prefix needed. Reach for uvr again only when dependencies change (uvr sync/uvr update) or for headless script execution (uvr run <script>.R, used by just test/CI, since it also finds the right R binary).
π§ͺ Common Tasks
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 R (via uvr) and dependencies (uvr sync)
update # Upgrade packages to the latest versions available (uvr update)
lint # Lint (Jarl check)
format # Format (Air format)
typecheck # Static type/scope check (ry)
test # Run testthat
docs-build # Build docs (box + rd2qmd generate reference md, Quarto renders the site)
pre-commit-install # Install git hooks (via prek)
pre-commit # Run all git hooks (via prek)π Documentation
π Releases
Managed by release-please: conventional commits drive semantic versioning and an autogenerated NEWS.md.
- Configuration: release-please-config.json
- Version source: uvr.toml
π Project Structure
.
βββ 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
βββ scripts/ # Helper scripts run via `uvr run` (tests, API reference generation)
βββ 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 rd2qmd (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
β βββ ISSUE_TEMPLATE/ # Bug report and feature request templates
β βββ pull_request_template.md
β βββ dependabot.yml # Weekly GitHub Actions updates
βββ .devcontainer/ # Dev container configuration
β βββ devcontainer.json
β βββ Dockerfile
βββ .vscode/ # Recommended extensions and editor settings
βββ uvr.toml # Project metadata + dependencies (uvr)
βββ uvr.lock # Locked dependency versions (uvr)
βββ .r-version # Pinned exact R version (uvr)
βββ .Rprofile # Adds .uvr/library to .libPaths() in interactive sessions (uvr)
βββ air.toml # Formatter configuration (air)
βββ jarl.toml # Linter configuration (jarl)
βββ ry.toml # Static checker configuration (ry)
βββ README.md # Project overview (you are here)
βββ CITATION.cff # Citation metadata
βββ CONTRIBUTING.md # Contribution guidelines
βββ CODE_OF_CONDUCT.md # Code of conduct
βββ CLAUDE.md # Guidance for AI coding assistants
βββ 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).
π€ Contributing
Use conventional commit messages (feat:, fix:, docs:, etc.). Ensure:
- Lint, format & ry check 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.
π Citation
If used in research, cite via CITATION.cff.
π‘ License
BSD-3-Clause β see LICENSE.
Happy coding! π