Development guidelines for quanteda
Source:AGENTS.md
Scope and approach
These instructions apply to the entire repository. Follow existing code and documentation conventions, and assess proposed changes critically before implementing them. Preserve public behaviour unless a change is intentional and documented.
Project overview
quanteda is an R package for the quantitative analysis of textual data. Its core objects and operations cover corpora and document variables, tokenisation and token manipulation, dictionaries, document-feature matrices (dfm), feature-co-occurrence matrices (fcm), and supporting text-analysis utilities.
The package combines R and Rcpp/C++ code. Changes to object construction, external-pointer tokens, indexing, or serialization can affect both layers and should be tested across the relevant object types.
Repository structure
-
R/: R source, S3 methods, validators, and user-facing APIs. -
src/: Rcpp/C++ implementation. -
inst/include/: installed C++ headers used by quanteda and extensions. -
tests/testthat/: unit and regression tests. -
tests/data/: test fixtures;tests/data_creation/contains data-generation scripts. -
man/: roxygen2-generated help files; do not edit these manually. -
vignettes/: package vignettes and long-form documentation. -
vignettes/pkgdown/: source material used for the package website. -
_pkgdown.yml: pkgdown navigation and configuration. -
docs/: generated pkgdown site. -
data/: packaged example data. -
DESCRIPTION: package metadata, version, dependencies, and collation order. -
NAMESPACE: generated by roxygen2; do not edit manually. -
.github/workflows/: R CMD check, coverage, and R-hub workflows.
R conventions
- Use two-space indentation and no tabs.
- Use
snake_casefor functions, arguments, and objects, following nearby code. - Keep high-level functions above their helpers where practical.
- Prefer clear base R code and namespace-qualified calls for non-imported functions.
- Match the repository’s existing error-handling patterns, including validators,
message_error(), andstop(). Do not introduce a new error framework without an intentional project-wide decision. - Use British English in prose, consistent with
Language: en-GBinDESCRIPTION. - End text files with a newline.
Documentation and generated files
- Document exported functions with roxygen2, including complete
@paramand@returnsections and useful examples where appropriate. - Add
@exportor the appropriate S3 registration tags for public APIs. - Run
devtools::document()after changing roxygen comments. - Review generated changes to
man/andNAMESPACE; do not edit them directly. - After changing an Rcpp-exported interface, run
Rcpp::compileAttributes()and review the generated changes toR/RcppExports.Randsrc/RcppExports.cpp. - Treat
docs/as generated output. Change_pkgdown.yml, roxygen source, or vignette source first, then regenerate the site withpkgdown::build_site(). - Add new reference topics to
_pkgdown.ymlwhen they need explicit placement. - Add a concise
NEWS.mdbullet for user-visible changes. Put function names in code font and reference the issue or PR and contributor when applicable.
Testing
- Add focused regression tests for bug fixes and tests for new behaviour.
- Place tests with the most closely related existing tests; source and test files do not need a strict one-to-one naming relationship.
- Cover typical inputs, edge cases, errors, empty objects, and relevant object representations.
- Keep tests deterministic and avoid network access.
- Start with the narrowest relevant test file, then run the broader suite in proportion to the change.
Useful commands from a clean R session include:
devtools::test(filter = "tokens")
devtools::test(reporter = "check")
covr::package_coverage()Do not claim a particular testthat edition unless it is explicitly configured in DESCRIPTION.
Building and checking
Use clean, reproducible R sessions where practical:
For normal development checks:
For a CRAN-style command-line check:
Review the tarball name if multiple local builds exist.
For website changes:
pkgdown::check_pkgdown()
pkgdown::build_site()C++ and Rcpp changes
- Keep the R and C++ representations of quanteda objects consistent.
- Treat code in
inst/include/as a potentially public C++ interface. - Check ownership, copying, and mutation semantics carefully for external pointers.
- Test both ordinary
tokensandtokens_xptrpaths when shared behaviour is affected. - Run package compilation and the relevant tests after modifying headers or files under
src/.
Git and pull requests
- Keep changes scoped and preserve unrelated work already present in the tree.
- Use concise, imperative commit subjects, for example
Fix token type lookup. - Base pull requests on
masterunless the task specifies another branch. - In a PR description, explain the motivation, user-visible behaviour, main implementation changes, tests, and documentation updates.
- Confirm the GitHub Actions R CMD check and coverage results for changes that affect package code.
Security and reproducibility
- Never commit API keys, access tokens, credentials, or private data.
- Do not make unit tests depend on external services.
- Record relevant R and package versions when diagnosing environment-specific failures.
Before finishing
- Inspect the final diff for accidental generated or unrelated changes.
- Run the checks appropriate to the risk and scope of the change.
- Report what was tested and anything that could not be tested.
- Do not describe a suggestion as an improvement until its trade-offs and fit with quanteda have been evaluated.