Repository navigation
Add AGENTS.md agent instructions - #72
Conversation
Documents build/test/document commands, the method-dispatch architecture used by the multi-method calc_* functions, vectorization and return-value conventions, and the workflow for adding a new published equation. Also excludes AGENTS.md from the built package via .Rbuildignore so R CMD check --as-cran does not flag a non-standard top-level file. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
roninsightrx
left a comment
There was a problem hiding this comment.
Changes requested: AGENTS.md currently gives agents commands and conventions that are factually incompatible with this branch.
AGENTS.md:28— The standalonetestthat::test_file("tests/testthat/test_calc_egfr.R")command does not load the package under test. In a clean export of this branch it produced 21 failures becausecalc_egfr()was not found. Replace it with the already documenteddevtools::test(filter = "calc_egfr"), or load the package first (for example,devtools::load_all(); testthat::test_file(...)).AGENTS.md:88-113—calc_ibw()is named as an example of this wrapper/inner-function pattern, but it does not follow the stated rule: it uses separatemethod_childrenandmethod_adultsarguments, itsibw_standard()andibw_devine()helpers perform validation and emit warnings, and the wrapper returns a bare numeric vector. Removecalc_ibw()from this example or document it explicitly as a legacy exception so an agent does not refactor it under a false invariant.AGENTS.md:149-150— The claim that clinical quantity functions returnlist(value, unit)and acceptdigitsis not a package-wide convention. For example,calc_bmi(),calc_abw(), andcalc_ibw()return numeric values and do not acceptdigits. Narrow this statement to the functions that actually use that interface and tell agents to preserve each exported function's existing return contract.AGENTS.md:151-156— Unit-conversion APIs and unit registries are not uniform as described.weight2kg(value, unit)and the helpers inmetric_conversion.Rreturn numeric values;conc2mol()/mol2conc()useunit_concandunit_mol; andconvert_conc_unit(),conc2mol(), andmol2conc()maintain unit tables outsidevalid_units(). Split this into the actual conversion families and direct agents to the registry/table used by the function they are changing.
Reviewed by Codex
- Drop the standalone `testthat::test_file()` command: it does not load the package and fails with "could not find function". Note the caveat and point at `devtools::load_all()` / `devtools::test(filter = ...)` instead. - Remove `calc_ibw()` from the method-dispatch example and document it as a legacy exception, so it is not refactored under a false invariant. - Narrow the return-value conventions: `list(value, unit)` and `digits` are not package-wide. List which functions use which shape and tell agents to preserve each function's existing contract. - Split the unit-conversion section into the actual families, since `unit_in`/`unit_out` and `valid_units()` are not universal: `conc2mol()`/`mol2conc()` use `unit_conc`/`unit_mol`, `convert_conc_unit()` keeps its own factor table, and `convert_flow_unit()`/`weight2kg()` return bare numerics. Also make the roxygen2 caveat precise: roxygen2 8.x replaces `RoxygenNote` with `Config/roxygen2/version` rather than bumping it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
All four findings verified against the source on this branch and all four were correct. Fixed in 11273c6. 1. 2. 3. 4. Unit-conversion APIs/registries not uniform — Confirmed: One extra: running 🤖 Generated with Claude Code |
roninsightrx
left a comment
There was a problem hiding this comment.
Not ready to approve: the original findings are substantially addressed, but three factual mismatches remain in the revised guidance.
AGENTS.md:92-117— The namedcalc_ffm()andcalc_egfr()implementations do not uniformly have pure inner functions with all validation in the wrapper.ffm_bucaloiu()checks method applicability and emits a warning, whileegfr_bedside_schwartz()checks age and emits a warning controlled byverbose. Qualify this as the general pattern while documenting that method-specific applicability checks can remain in inner functions, or move those checks into the wrappers before retaining the absolute wording.AGENTS.md:162-168— The revised return-shape inventory still drops public fields:calc_ffm()andcalc_creat()returnmethodin addition tovalueandunit. Also,cappedin thecalc_egfr()result is cap metadata, not a resolved covariate. Split those shapes or say the first group returns at leastvalue/unit, explicitly preserve themethodfield, and describecappedseparately from the resolved covariates.AGENTS.md:173-180— Extending onlyvalid_units()is insufficient when adding a spelling for these wrapper functions: the same spelling must also exist inconvert_conc_unit()'sconvtable or the delegate rejects it as unrecognized. Tell agents to keepvalid_units()and the factor table in sync for units handled through these wrappers.
Reviewed by Codex
mccarthy-m-g
left a comment
There was a problem hiding this comment.
In addition to the "three factual mismatches remain in the revised guidance", some additional suggestions and comments. The broader point on keeping unified instructions across our repos might be worth a group discussion on how to best handle that.
My current idea is that we just have an additional instruction that tells the agent if it updates a generic instruction in this repo it should also prompt us to update those instructions in our other repos. Although that would be a pain since we have a lot of repos. Is there some way we can have a single "Basic R package instructions" generic in a public repo that the repo-specific AGENTS.md can all reference?
| `testthat::test_file()` on its own does not load the package under test and | ||
| will fail with "could not find function". Call `devtools::load_all()` first in | ||
| the same session, or just use `devtools::test(filter = ...)`. |
There was a problem hiding this comment.
is this necessary given the way to do this is documented above?
There was a problem hiding this comment.
Agreed — condensed to one line that just names the subset command and the reason not to reach for testthat::test_file(), since an agent's default instinct is to use it.
| Command line equivalents: | ||
|
|
||
| ```sh | ||
| R CMD build . && R CMD check --as-cran clinPK_*.tar.gz | ||
| Rscript -e 'devtools::test()' | ||
| ``` |
There was a problem hiding this comment.
Equivalents to what? The agent could probably use more context here
There was a problem hiding this comment.
Reworded to "Equivalent checks from a shell, for a CI-like run or when working outside an R session". Note CI actually runs these via rcmdcheck in the r-lib action rather than literally, so I avoided claiming it is exactly what CI runs.
| CI (`.github/workflows/R-CMD-check.yaml`) runs `R CMD check` with | ||
| `--no-manual --as-cran` on ubuntu-latest / R release, and fails on errors | ||
| (warnings and notes do not fail the build). A second workflow builds the | ||
| pkgdown site from `_pkgdown.yml`. |
There was a problem hiding this comment.
We have this in the command examples for InsightRX/mipdeval#51 but not not in the examples here despite there also being a pkgdown site.
# Build pkgdown site
pkgdown::build_site()We should make sure generic agent instructions are unified across repos for consistency. Might need to add additional instructions to each one that prevent drift across repos too.
There was a problem hiding this comment.
Added pkgdown::build_site() to the command block and named the workflow (.github/workflows/pkgdown.yaml, which uses build_site_github_pages() on pushes to master). The cross-repo unification and anti-drift instruction is deferred for team discussion.
| (warnings and notes do not fail the build). A second workflow builds the | ||
| pkgdown site from `_pkgdown.yml`. | ||
|
|
||
| ### Documentation is generated |
There was a problem hiding this comment.
Similar comment here: In mipdeval's agent instructions documentation instructions are a footnote at the bottom in the General notes section. I think the unique heading approach here is nicer. We should unify whatever documentation instructions we want across repos.
There was a problem hiding this comment.
No local change needed since you prefer the dedicated-heading approach used here; unifying the documentation-instructions layout across repos is deferred for team discussion.
| `git diff` after documenting and keep the diff limited to the functions you | ||
| actually changed. | ||
|
|
||
| ### Package data |
There was a problem hiding this comment.
Similar point here. We give different details on how data-raw works in this package than in mipdeval. Some of this is because they're doing slightly different things, but there's probably room to unify better since we're broadly using data-raw to "preserve the origin story of package data" (https://r-pkgs.org/data.html#sec-data-data-raw)
There was a problem hiding this comment.
Added the framing that data-raw/ preserves the origin story of the package data, with the r-pkgs link, kept above the clinPK-specific growth-chart detail. Broader unification with mipdeval deferred for team discussion.
| testthat edition 3, tests in `tests/testthat/`. File naming is inconsistent | ||
| (`test_foo.R` and `test-foo.R` both occur) — match the neighbouring files for |
There was a problem hiding this comment.
inconsistent naming is possibly my fault. I use usethis::use_test() to create new test files from the currently active script when writing new functions. It uses the test- separator, but our historic convention is test_ and it's easy to miss which is being used in a review since it's a tiny detail.
My personal suggestion would be to do some tech-debt cleanup and make all our repos use test-, and then drop this file naming comment from the instructions. Or if we want to stick to the historic convention make that an explicit agent instruction in all our repos
There was a problem hiding this comment.
Made the convention explicit: name new files test_<topic>.R, and noted that usethis::use_test() produces the hyphenated form so it needs renaming (64 files use test_, 6 use test-). Tech-debt renaming across repos is deferred for team discussion.
Codex follow-up: - Qualify the method-dispatch rule: method-specific applicability checks may stay in the inner function (`ffm_bucaloiu()`, `egfr_bedside_schwartz()`) instead of claiming inner functions do no validation at all. - Correct the return-shape inventory: `calc_ffm()` and `calc_creat()` also return `method`, and `capped` in the `calc_egfr()` result is cap metadata rather than a resolved covariate. - Note that adding a unit spelling means editing both `valid_units()` and the `conv` table in `convert_conc_unit()`, since the delegate rejects unknown spellings. Reviewer suggestions: - Add `pkgdown::build_site()` to the commands and name the pkgdown workflow. - Explain what the shell block is equivalent to, and condense the `testthat::test_file()` caveat now that the subset command is documented. - Describe `data-raw/` as preserving the origin story of the package data. - State the `test_<topic>.R` naming convention explicitly and note that `usethis::use_test()` produces the hyphenated form. Also move the general return-value notes out of the unit-conversion list and give unit conversion its own heading. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Round 3 pushed in 1f36e6e. All three Codex follow-up findings verified against source and all three were correct; all six inline comments answered on their threads. Codex follow-up
Reviewer suggestions (@mccarthy-m-g)
Deferred for team discussion — the cross-repo questions are all out of scope for this PR and nothing in other repos was touched: a shared "Basic R package instructions" doc that repo-specific AGENTS.md files reference, an anti-drift instruction to prompt updates in sibling repos, unifying the documentation-instructions layout and the File stays harness-agnostic (no agent product names) at 267 lines. Full suite green: 678 assertions, 0 failures. CI on this branch is passing. 🤖 Generated with Claude Code |
Adds an
AGENTS.mdat the repo root with instructions for AI coding agents working on clinPK.What it contains
devtools::test(), running a single test file,devtools::document(),devtools::check(), and theR CMD build/check --as-cranequivalents, plus what CI actually runs.man/*.RdandNAMESPACEare roxygen2 output and must not be hand-edited, with a note about theRoxygenNote: 7.3.2pin causing.Rdchurn under newer roxygen2.R/naming conventions (calc_*,pk_1cmt_*/pk_2cmt_*suffix grammar,pct_*_for_*,nca*), and the method-dispatch pattern: a validating wrapper plus small pure<quantity>_<method>()equation functions, backed bycheck_input_lengths(),prepare_method_inputs()andnormalize_sex()inR/utils.R.ifelse()overif,vapply()oversapply()), thelist(value =, unit =)return shape, centralizing unit strings invalid_units(), relative vs. absolute eGFR, testthat practices, commit/branch style, and CRAN backwards-compatibility constraints.NEWS.md.Why AGENTS.md and not CLAUDE.md
AGENTS.mdis the emerging cross-harness convention, so the same file is picked up by other agent tooling rather than only one vendor's. The content is written harness-agnostically and refers to "agents" rather than any specific product.AGENTS.mdis added to.RbuildignoresoR CMD check --as-crandoes not flag it as a non-standard top-level file.Verified by running
devtools::test()on this branch: 678 passing, 0 failures.🤖 Generated with Claude Code