From c054515d7f8254f43d679d29ed7ed2350ac4cd5c Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 4 Aug 2026 16:21:58 -0500 Subject: [PATCH 1/2] Document the _PACKAGE sentinel in README and CLAUDE.md (#30) The feature has existed since 302b484 and gained the base-R macro style in #11, but neither README nor CLAUDE.md mentioned it, so #30 was filed requesting a feature tinyrox already had. Docs-only; no version bump. --- CLAUDE.md | 6 ++++++ README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index ca192d3..9162223 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -33,6 +33,12 @@ r -e 'tinyrox::document()' ### Namespace `@export`, `@exportS3Method`, `@exportClass`, `@import`, `@importFrom`, `@useDynLib` +### Package-level docs +A block attached to the `"_PACKAGE"` sentinel generates `man/pkg-package.Rd` +(aliases `pkg` and `pkg-package`). Title/description/author/maintainer come +from DESCRIPTION via base-R Rd macros; block paragraphs 3+ (or `@details`) +fill `\details{}`. Nothing is added to NAMESPACE. + ## What it does NOT do - Markdown parsing diff --git a/README.md b/README.md index aff9c6e..e7b07cd 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,32 @@ add <- function(x, y) { } ``` +## Package-Level Documentation + +Attach a block to the `"_PACKAGE"` sentinel (same convention as roxygen2) to +generate a `?pkgname` landing topic: + +```r +#' mypkg: One-Line Title +#' +#' This paragraph is ignored; the help page pulls the description from +#' DESCRIPTION instead (see below). +#' +#' Paragraphs three and beyond (or @details) become \details{}: design +#' notes, limitations, getting-started prose. +#' @keywords internal +"_PACKAGE" +``` + +This writes `man/mypkg-package.Rd` with package `docType` and aliases for +`mypkg` and `mypkg-package`, so `?mypkg` resolves. Title, description, +author, and maintainer come from `DESCRIPTION` at render time via the base-R +Rd macros (`\packageTitle{}`, `\packageDescription{}`, `\packageAuthor{}`, +`\packageMaintainer{}`). DESCRIPTION stays the single source of truth, and +the block's title and description paragraphs are not copied into the Rd. A +function index is generated with `\packageIndices{}`. The sentinel is not +exported and adds nothing to `NAMESPACE`. + ## CRAN Compliance Checking tinyrox includes automated CRAN compliance checks: From cf9a707cb898162410ecfb353ade98004ed76ed2 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 4 Aug 2026 16:34:50 -0500 Subject: [PATCH 2/2] Address review: fix Rd command in copyable example, honest @author row, document()-level test - The README example's prose contained a literal \details{} which, once the example is copied and documented, sits inside the generated \details section and makes tools::parse_Rd() warn about an unexpected section header. Reworded; the copied example now parses clean. - The @author table row claimed package-level support, but every generator ignores tags$author in favor of the DESCRIPTION macros. Row now says so. - New tinytest fixture runs the full tinyrox::document() flow on a _PACKAGE package: docType and both aliases present, NAMESPACE carries only the real export, re-document is byte-identical, and prune_rd leaves the package topic alone. --- README.md | 6 ++--- inst/tinytest/test_rd.R | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7b07cd..c72ce20 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ check_cran() | `@seealso` | Cross-references | | `@references` | Citations | | `@section Title:` | Custom section (package-level docs only) | -| `@author` | Author information (package-level docs only) | +| `@author` | Accepted for roxygen2 compatibility; ignored (authors come from `DESCRIPTION`) | | `@aliases` | Additional topic aliases | | `@keywords` | Rd keywords (e.g., `internal`) | | `@name` | Explicit topic name | @@ -89,8 +89,8 @@ generate a `?pkgname` landing topic: #' This paragraph is ignored; the help page pulls the description from #' DESCRIPTION instead (see below). #' -#' Paragraphs three and beyond (or @details) become \details{}: design -#' notes, limitations, getting-started prose. +#' Paragraphs three and beyond (or @details) become the details +#' section: design notes, limitations, getting-started prose. #' @keywords internal "_PACKAGE" ``` diff --git a/inst/tinytest/test_rd.R b/inst/tinytest/test_rd.R index cb51d04..fff1951 100644 --- a/inst/tinytest/test_rd.R +++ b/inst/tinytest/test_rd.R @@ -342,3 +342,56 @@ tags31 <- list( rd31 <- tinyrox:::generate_rd(tags31, list(names = character(), usage = character())) expect_true(grepl('sprintf("\\%d of \\%d", 1)', rd31, fixed = TRUE)) + +# --- Issue #30 acceptance: _PACKAGE through the full document() flow --- +test_package_sentinel_document <- function() { + pkg <- file.path(tempdir(), "sentpkg") + on.exit(unlink(pkg, recursive = TRUE), add = TRUE) + dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE) + writeLines(c( + "Package: sentpkg", "Title: T", "Version: 0.0.1", + "Description: D.", + "Authors@R: person('A', 'B', email='a@b.c', role=c('aut','cre'))" + ), file.path(pkg, "DESCRIPTION")) + writeLines(c( + "#' sentpkg: Test Package.", + "#'", + "#' Ignored description paragraph.", + "#'", + "#' Details paragraph.", + "#' @keywords internal", + "\"_PACKAGE\""), + file.path(pkg, "R", "sentpkg-package.R")) + writeLines(c( + "#' Identity", + "#' @param x A value.", + "#' @return x.", + "#' @examples", + "#' ident(1)", + "#' @export", + "ident <- function(x) x"), + file.path(pkg, "R", "ident.R")) + + tinyrox::document(pkg, cran_check = FALSE, silent = TRUE) + + # Package topic generated with docType and both aliases (?sentpkg resolves) + rd_path <- file.path(pkg, "man", "sentpkg-package.Rd") + expect_true(file.exists(rd_path)) + rd <- readLines(rd_path) + expect_true("\\docType{package}" %in% rd) + expect_true("\\alias{sentpkg}" %in% rd) + expect_true("\\alias{sentpkg-package}" %in% rd) + expect_true("Details paragraph." %in% rd) + + # NAMESPACE holds the one real export and nothing for the sentinel + ns <- readLines(file.path(pkg, "NAMESPACE")) + expect_equal(grep("^export", ns, value = TRUE), "export(ident)") + expect_false(any(grepl("_PACKAGE", ns, fixed = TRUE))) + + # Re-documenting is idempotent and prune_rd leaves the package topic alone + res2 <- tinyrox::document(pkg, cran_check = FALSE, silent = TRUE, + prune_rd = TRUE) + expect_equal(readLines(rd_path), rd) + expect_equal(res2$pruned, character(0)) +} +test_package_sentinel_document()