Contributing
Source:.github/CONTRIBUTING.md
Contributions to iheiddown, whether in the form of issue identification, bug fixes, new templates, new code or documentation, are encouraged and welcome.
Please note that the iheiddown project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Contents
Each entry says when to read the section. Update this list whenever a heading below is added, renamed, or moved.
- Identifying issues: before you report a bug or ask for a feature
-
Package architecture
- Project overview: to find where a format, template or tool lives
- How a format is built: before you change or add an output format
- Statements on the use of generative AI: before you change the AI statement, or add a format
- Design principles: before you add a dependency, a function, or an argument
-
Developing
- Common commands: to load, document, test, or check the package
- Dependencies: before you use a function from another package
- Console messaging: before you write an error, a warning, or a message
- Tests: before you add a test
-
Documenting
- README and website: before you edit the README or the website
-
NEWS.mdconventions: before you write aNEWS.mdentry or a commit message
-
Releasing
- Branching and CI: to choose a branch, or to read a failed check
- Git for new contributors: if git is new to you
Identifying issues
Please use the issues tracker on GitHub to identify any issues. You can use these issues to track progress on the issue and to comment or continue a conversation on that issue. The most useful issues are ones that precisely identify an error, or propose a test that should pass but instead fails. For a rendering problem, please give the template, the operating system, the versions of R, Pandoc and LaTeX, and the end of the .log file.
Package architecture
Project overview
iheiddown gives students and faculty of the Geneva Graduate Institute output formats and templates for documents that follow the Institute’s conventions and regulations, and a few tools that help to write them.
| What | Where |
|---|---|
Output format functions, e.g. thesis_pdf(), syllabus_pdf()
|
R/<format>.R |
Template skeletons that rmarkdown::draft() copies for the user |
inst/rmarkdown/templates/<template>/skeleton/ |
| LaTeX and HTML templates that Pandoc fills | inst/rmarkdown/templates/<format>/resources/ |
| Lua filters that Pandoc runs (the Quarto extensions use them too) | inst/rmarkdown/lua/ |
| Quarto extensions: one format for each template | inst/quarto/_extensions/iheid-<template>/ |
Quarto starter files that use_quarto() copies |
inst/quarto/templates/<template>/ |
| The Institute’s colours and fonts for Quarto | inst/quarto/_brand.yml |
| The script that makes the PowerPoint reference document of the slides | data-raw/make-pptx-reference.py |
| Palettes and the ggplot2 theme |
R/palettes.R, R/theme.R
|
| Word counts and bibliography statistics |
R/count_words.R, R/bibstats.R, R/bibfix.R
|
Shared helpers, e.g. active_file()
|
R/utils.R |
| The script that renders all templates for CI and the website |
R/_render.R (not in the built package) |
How a format is built
An output format function reads what it needs from the YAML header with yaml_field(), which uses rmarkdown::yaml_front_matter(). Do not read the YAML header line by line. The function then calls rmarkdown::pdf_document(), bookdown::pdf_book() or another base format with the template from resources/, and adds the Lua filters with add_lua_filters().
The LaTeX templates must work with Pandoc 3.1.8 and later. Copy definitions that Pandoc needs, such as the citeproc block, from pandoc --print-default-data-file templates/common.latex, and say in a comment where they come from.
If you add a template, also add it to R/_render.R, so that CI renders it on every pull request.
Statements on the use of generative AI
Every output format adds a statement on the use of generative AI from the ai-statement field in the YAML header. The text is made in two places, which must stay in step:
-
inst/rmarkdown/lua/ai-statement.lua, for all formats that use Pandoc; -
ai_statement()inR/ai_statement.R, for formats that do not, such as xaringan presentations.
tests/testthat/test-ai_statement.R runs both on the same inputs and fails if the text is different. Every template skeleton must have an ai-statement field, and a test checks this too. If you change the wording, make sure it agrees with the current regulations of the Institute.
Design principles
- Few dependencies. Students install this package on their own computers, often with little experience of R. Every dependency is a possible installation failure. A function that only some users need gets its package from Suggests (see Dependencies). Prefer base R to a new package where the code stays short and clear.
-
Works outside RStudio. Functions take the file as an argument. They can use the file open in the editor only as a default, through
active_file(), which works in RStudio and Positron and gives a clear error elsewhere. -
No network by default. A function that sends data to an external service, such as
percent_female(), says so in its documentation, and runs only when the user calls it. - Templates render as they are. A template skeleton must render without changes on a new installation. A chunk that needs a package from outside CRAN, or from outside Suggests, is not allowed.
Developing
Common commands
This is a standard R package developed with devtools/roxygen2. Run these from an R console with the working directory set to the package root (or via Rscript -e).
- Load for development:
devtools::load_all() - Regenerate docs and NAMESPACE after editing roxygen comments:
devtools::document() - Run the full test suite:
devtools::test() - Run a single test file:
devtools::test(filter = "ai_statement") - Full package check (mirrors CI):
devtools::check()orrcmdcheck::rcmdcheck() - Render all templates as CI does:
Rscript R/_render.R, from an empty folder - Code coverage:
covr::package_coverage() - Build the website locally:
pkgdown::build_site()
Run R in a UTF-8 locale, e.g. LANG=en_US.UTF-8 Rscript -e "devtools::document()". Under the C locale, knitr::write_bib() in the templates fails on names with accented letters, and devtools::document() writes byte escapes into man/.
Dependencies
Imports are only bookdown, cli, ggplot2, rlang and rmarkdown. Before you add a package to Imports, ask in an issue.
A package that only one function needs goes in Suggests. Call rlang::check_installed() at the start of that function, with a reason, so that the user gets the install command:
rlang::check_installed("pdftools", "to read the text of a PDF.")Then call the package with ::. Do not use @importFrom for a package in Suggests.
Console messaging
All user-facing messages use cli: cli::cli_abort() for errors, cli::cli_warn() for warnings, and cli::cli_inform() for messages. Do not use base message(), warning() or stop().
- Braces interpolate, in place of
paste():cli::cli_abort("No PDF found at {.path {file}}."). - Use the cli inline classes
{.fn},{.arg},{.val},{.path},{.file},{.pkg}and{.url}for what you refer to. - Give the next action in a bullet:
c("No {.file .bib} file found.", "i" = "Please give {.arg bib_file}.").
A warning says that the function continued, but that the user should not trust the result without knowing something. An error carries everything that the user needs to act.
Tests
This package uses testthat edition 3. Tests in tests/testthat/ mirror the R/ files.
-
No network. Mock external services with
testthat::local_mocked_bindings(), astest-bibstats.Rdoes for gender. -
No extra test packages. Use
tempfile()for temporary files. Do not add withr or other packages only for tests. -
Skip what needs a Suggests package with
skip_if_not_installed(), and what needs Pandoc withskip_if_not(rmarkdown::pandoc_available("2.17")). -
Rendering. The tests that render a template use
render_template()andskip_if_cannot_render()fromhelper-render.R. They do not run on CRAN, or where XeLaTeX or a package that the template needs is not available. CI also renders all templates withR/_render.R, in a separate job.
Documenting
README and website
README.md is generated from README.Rmd: edit README.Rmd and render it with rmarkdown::render("README.Rmd", output_format = "md_document"). The website is built with pkgdown from pkgdown/_pkgdown.yml. When you export a function, add it to the reference: section there, or the website build fails. The examples menu of the website links to the files that R/_render.R writes to docs/sample_output/.
NEWS.md conventions
NEWS.md groups each version’s changes under ## headings. Lead with ## Package (package-wide, website and infrastructure changes), then the areas of the package in this order: ## AI statements, ## Quarto, ## Thesis, ## Syllabus and problem sets, ## Presentations, ## Posters, ## Bibliography, ## Word counts, ## Graphics, and last ## Tests. Each heading appears at most once per version.
Start each bullet with a verb that matches the change type:
-
Added ...— new functionality -
Fixed ...— bug fixes; if it relates to a GitHub issue, suffix with(closes #123). Note that GitHub closes the issue only where the same phrase is in a commit message or the pull request description -
Renamed ... to ...— function or argument name changes -
Improved ...— functional updates to existing behaviour -
Updated ...— documentation changes -
Removed .../Dropped ...— functionality or dependencies taken out -
Moved .../Replaced ...— functionality relocated or substituted
Keep every bullet to one line of fewer than 81 characters if you can. Where several changes concern one function, lead with an Improved ... bullet that names the function, and put the individual Fixed .../Added ... points beneath it as sub-bullets, indented by two spaces. A function leads at most one bullet in a version.
If a cited GitHub issue was not authored by @jhollway, thank the author with an @-tag in the bullet.
Releasing
Branching and CI
-
mainis the release branch;developis the working branch. - Pull requests into
maintrigger prchecks.yml: R CMD check (macOS, Windows and Linux), a binary build, code coverage, a render of all templates, and PR metadata checks. The metadata checks require that:- the
VersioninDESCRIPTIONis greater than onmain; - the PR title names the new version;
- the PR description lists the changes under
##headings, as inNEWS.md.
- the
- Merges into
maintrigger pushrelease.yml: check, render, a tag for theDESCRIPTIONversion, a GitHub release with the binaries, the example PDFs and theNEWS.mdsection as notes, and then the website. - If the render job fails, the job prints the end of each
.logfile. Look there first for LaTeX errors.
Git for new contributors
iheiddown is maintained using the git version control system. A plain-English introduction to git can be found here, and a more recent motivation here. They explain the basics of git version control: committing and repos, pulling and pushing, branching and merging.
Using git from the command line can be intimidating, so we recommend Fork software for Mac and Windows, which allows mostly visual management of commits, diffs, and branches.
-
Clone the remote repository to your computer, and work on the
developbranch. - Pull before you start working, so that you have the newest commits and files.
-
Commit once you have saved a change: check the diff one last time, and write a commit message in the form of a
NEWS.mdbullet (see above), with the issue it relates to. - Push the commit to the remote repository, making sure the branch is the one you worked on.