This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Maintainer's General Instructions:Source
- Before writing any code, describe your approach and wait for approval.
- If the requirements I give you are ambiguous, ask clarifying questions before writing any code.
- After you finish writing any code, list the edge cases and suggest test cases to cover them.
- If a task requires changes to more than 3 files, stop and break it into smaller tasks first.
- When there’s a bug, start by writing a test that reproduces it, then fix it until the test passes.
- Every time I correct you, reflect on what you did wrong and come up with a plan to never make the same mistake again.
naijR is an R package (rOpenSci-reviewed, on CRAN) providing convenience functions and geopolitical data for Nigeria. Key domains: administrative regions (States/LGAs), geospatial mapping, phone number correction, and inter-city distances.
# Check package (full R CMD check)
R CMD check .
# Run all tests
Rscript -e 'testthat::test_local()'
# Run a single test file
Rscript -e 'testthat::test_file("tests/testthat/test-regions.R")'
# Build documentation (roxygen2)
Rscript -e 'roxygen2::roxygenise()'
# Lint
Rscript -e 'lintr::lint_package()'
# Install locally for testing
R CMD INSTALL .Tests use testthat edition 3 (configured in DESCRIPTION).
The package defines two core S3 classes: states and lgas. These have custom methods for print, [, [[, c, and na.exclude. The fix_region generic dispatches on these classes plus a default method.
Files ending in int contain internal (non-exported) helper functions for the corresponding public module:
regions.R/regionsint.R—states(),lgas(), constructors, validators, coercion (as_state,as_lga,is_state,is_lga)map.R/mapint.R—map_ng()and internal mapping helpers (usessf,maps,mapdata)fixreg.R/fixregint.R—fix_region()S3 methods andfix_region_manual()for correcting misspelled region namesfixmob.R—fix_mobile()for Nigerian phone number normalizationdistances.R—ng_distance()for road distances between state capitalsdisambi.R—disambiguate_lga()for States/LGAs that share namesfct.R— Helpers for handling Federal Capital Territory (FCT) special caseshelpers.R— Shared internal utilitiesregdata.R— Documentation for package datasetszzz.R—.onLoadhook (sets choropleth colour options)
data/states_nigeria.rda,data/lgas_nigeria.rda— Exported datasets of States and LGAsdata/ngdist.rda— Road distance matrix between state capitalsR/sysdata.rda— Internal data (shapefile objectsshp.state,shp.lgaused by mapping)data-raw/— Source shapefiles and scripts for regenerating.rdafiles
- Uses
clifor user-facing warnings/errors (cli_abort,cli_warn) - Uses
rlangfor non-standard evaluation and internal error signaling stringi::stri_trans_totitlefor case-insensitive name matching- Linting uses default
lintrrules (.lintrconfig) - README.md is generated from README.Rmd — edit the
.Rmdfile, not the.md R/util.Ris excluded from the package build (in.Rbuildignore)
master— main/release branchdev— development branch- CI runs R-CMD-check on both
masteranddev