Document @keywords internal as the default for internal helpers#276
Document @keywords internal as the default for internal helpers#276d-morrison wants to merge 7 commits into
Conversation
Document the difference between the two tags and recommend @Keywords internal as the default for internal helpers: - @Keywords internal still generates the Rd file (so ?pkg:::fn works and future maintainers can read the docs), it just hides the function from the pkgdown reference and the package main help page. - @nord suppresses Rd generation entirely; reserved for cases where documentation genuinely doesn't help (one-line shims). Came up while standardizing internal-helper docs across an R-package project; folding the rule of thumb back into the lab manual so it's the canonical reference.
There was a problem hiding this comment.
Pull request overview
Adds guidance to the lab manual on how to document non-exported R helpers, clarifying the tradeoffs between @keywords internal and @noRd within the “Function Documentation” section.
Changes:
- Added a new subsection recommending
@keywords internalas the default for internal helpers. - Introduced a comparison table explaining behavioral differences between
@keywords internaland@noRd. - Added an example roxygen block demonstrating
@keywords internalusage.
|
|
@claude address #276 (review) |
|
Claude finished @d-morrison's task in 1m 2s —— View job Addressed copilot review feedback
The wording on line 142 was updated to make it clear that:
Change made ( -Two roxygen tags hide a function from the package's public surface,
-and they behave differently:
+A helper is kept internal by omitting `@export` (which keeps it out of `NAMESPACE`).
+Once the function is non-exported, two roxygen tags control how its documentation
+is generated and indexed, and they behave differently:| |
The previous wording implied these tags 'hide a function from the package's public surface', which is misleading. A function is kept internal by omitting @export (keeping it out of NAMESPACE); the two tags only control how documentation is generated and indexed. Co-authored-by: Douglas Ezra Morrison <d-morrison@users.noreply.github.com>
|
@claude review |
|
Claude finished @d-morrison's task in 1m 17s —— View job Code Review
The new section is well-structured, fills a real gap in the lab manual, and the previously flagged misleading wording (about "hiding from the public surface") has already been corrected in a prior commit. The core guidance is accurate and practical. A few observations: Minor issue — imprecise The prose says:
Using bare -so future maintainers (or future-you) can `?internal_helper` and see
-the documentation —
+so future maintainers (or future-you) can run `?pkg:::internal_helper` and see
+the documentation —Minor style inconsistency — capitalization in example ( All other #' @param row a one-row data frame.
#' @returns a numeric scalar.Consider capitalising to match: #' @param row A one-row data frame.
#' @returns A numeric scalar.Suggestion — table could note the The table's "Appears in pkgdown reference index?" column is accurate, but Overall the guidance is correct, clear, and a welcome addition. The two items above are polish-level and could be addressed before merging or in a follow-up. |
|
@claude address #276 (comment). one possible correction: check if ?pkg::function_name (no |
|
Claude finished @d-morrison's task in 1m 48s —— View job Addressed review feedback on
|
Use ?pkg:::internal_helper to match the table's notation and because pkg::fn (double colon) only works for exported functions; @Keywords internal helpers are non-exported, so ::: is required. Also capitalise @param and @returns descriptions in the example block to match sentence-case style used elsewhere in the file. Co-authored-by: Douglas Ezra Morrison <d-morrison@users.noreply.github.com>
|
@claude review |
|
Claude finished @d-morrison's task in 1m 14s —— View job Code Review
The new section is accurate, clearly written, and a genuine improvement to the lab manual. All issues from the previous review round have been correctly resolved (misleading wording, Minor issue — The example function uses score_one_row <- function(row) {
...
}Because the signature is Suggested fix: score_one_row <- function(row) {
### function code here
}Optional — note that Line 156–157 says the function "stays out of the pkgdown reference and the package's main help page." This is accurate — Observation — opening paragraph overlaps with page-level guidance Lines 137–140 re-state "Document every function you write, including internal helpers." The very first line of the page makes the same point. The repetition serves as useful motivation for the section, so this is a style choice rather than an error — just worth knowing if there's ever a page-level rewrite. Overall the content is correct, the prose is tight, and the section fills a real gap. The |
|
Claude Code CLI (local session) is working on this — paws off until I'm done. |
The previous '...' placeholder is syntactically invalid R for a function whose signature has no '...' formal. Match the placeholder convention used elsewhere in the file. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Addressed the one mechanical finding from the latest review: replaced the The other items in the review were explicitly marked Optional/Observation (style choices the reviewer said need no change), and the inline 'misleading wording' note about hiding from the public surface is already resolved by the current text (lines 142–144, which now explain a helper is kept internal by omitting @claude review |
|
Claude finished @d-morrison's task in 1m 1s —— View job Code Review
All issues from prior review rounds have been correctly resolved. Here's the current state:
The score_one_row <- function(row) {
### function code here
}No new issues found. The section is accurate:
This section is ready to merge. |
| A helper is kept internal by omitting `@export` (which keeps it out of `NAMESPACE`). | ||
| Once the function is non-exported, two roxygen tags control how its documentation | ||
| is generated and indexed, and they behave differently: |
|
Claude Code CLI (local session) is working on this — paws off until I'm done. |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| The question is *how* the documentation is exposed, | ||
| not whether it exists. | ||
|
|
||
| A helper is kept internal by omitting `@export` (which keeps it out of `NAMESPACE`). |
| |----------------------|:------------------------:|:------------------------------------:|:----------------------------:| | ||
| | `@noRd` | No | No | No | | ||
| | `@keywords internal` | Yes | No | Yes | | ||
|
|
|
@claude review |
|
Claude finished @d-morrison's task in 2m 40s —— View job Code Review
Three outstanding findings from the June 3 and June 17 Copilot reviews; all prior issues (misleading wording, Issue — This is the June 3 Copilot finding, which landed after the June 3 claude sign-off and hasn't been addressed yet. Line 142 reads: The phrase "keeps it out of Suggested fix: -A helper is kept internal by omitting `@export` (which keeps it out of `NAMESPACE`).
+A helper is kept internal by omitting `@export`
+(which keeps it out of the `NAMESPACE` exports).Issue — semantic line break missing on line 142 ( This is the June 17 Copilot finding. The copilot-instructions.md style guide explicitly requires: "ALWAYS line-break at the ends of sentences and long phrases … Break after approximately 60–80 characters." Line 142 is 84 characters and is a single complete sentence. The split above (separating the parenthetical onto its own line) resolves both this finding and the accuracy finding together. Issue — table has no link to source docs ( This is the June 17 Copilot finding. The table at lines 146–149 makes specific factual claims about The A similar closing line for this section would satisfy the Copilot finding and align with the file's existing style. Something like: For more details on `@keywords internal` and `@noRd`,
see the [roxygen2 documentation on special keywords](https://roxygen2.r-lib.org/articles/rd-other.html#keywords)
and [pkgdown's reference index documentation](https://pkgdown.r-lib.org/articles/pkgdown.html#reference).Summary
The content is accurate and a clear improvement to the lab manual. The three open items above are all straightforward fixes before merge. |
- Correct the inaccurate '(keeps it out of NAMESPACE)': the function is in the namespace; @export controls the export() directives (matches the table showing pkg:::fn works). Split onto its own line (semantic line break). - Add roxygen2 + R Packages source links after the tag table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds a subsection to
coding-practices/function-documentation.qmdcovering when to use
@keywords internalversus@noRdfor hidinginternal helpers.
The function-documentation page already covers `@inheritDotParams` and
the general "document every function" principle, but doesn't currently
distinguish the two tags. The new subsection:
via `?pkg:::fn`).
documentation still exists and is reachable, the function just doesn't
pollute the pkgdown reference.
shims).
Test plan
appears under "Function Documentation" with the table rendering
correctly.
reads well with the new section appended.