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..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 | @@ -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 the details +#' section: 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: 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()