Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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:
Expand Down
53 changes: 53 additions & 0 deletions inst/tinytest/test_rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading