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
1 change: 0 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
^\.github$
^CLAUDE\.md$
^\.claude$
^fyi\.md$
^cran-comments\.md$
^tools$
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ r -e 'tinyrox::document()'
## Supported Tags

### Documentation
`@title`, `@description`, `@details`, `@param`, `@return`, `@value`, `@examples`, `@seealso`, `@references`, `@aliases`, `@keywords`, `@name`, `@rdname`, `@noRd`, `@inheritParams`
`@title`, `@description`, `@details`, `@param`, `@return`, `@value`, `@examples`, `@examplesIf`, `@seealso`, `@references`, `@aliases`, `@keywords`, `@name`, `@rdname`, `@noRd`, `@inheritParams`

### Namespace
`@export`, `@exportS3Method`, `@exportClass`, `@import`, `@importFrom`, `@useDynLib`
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinyrox
Title: Minimal R Documentation Generator
Version: 0.4.1.3
Date: 2026-10-05
Version: 0.4.1.5
Date: 2026-11-24
Authors@R: c(
person("Troy", "Hernandez", email = "troy@cornball.ai", role = c("aut", "cre"),
comment = c(ORCID = "0009-0005-4248-604X")),
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# tinyrox 0.4.1.5

* `@exportS3Method pkg::generic` writes `S3method(pkg::generic,class)`, R's delayed registration for a generic the package does not import. It used to drop the `pkg::` prefix, and the two-argument form quoted it; either way the method was never registered. The class is the object name with `generic.` removed, and a name that does not start that way warns.
* `@examplesIf cond` is supported (#39). It was an unknown tag, so its examples were skipped with a warning and the page shipped with none. The output matches roxygen2: the guard sits in `\dontshow{}` and the help page shows only the example code. Several example tags on one block now all reach the page, in the order written; a second `@examples` used to replace the first.

# tinyrox 0.4.1.4

* A bare `@exportS3Method` registers the method (#37). With no argument the tag was dropped silently: no `S3method()` line and no export, so dispatch failed at runtime. Generic and class now come from the object name, a known or package-defined generic first (`as.data.frame.foo`), and a name with no dot to split on warns.
* `@param a,b desc` documents both formals for the undocumented-parameter check (#40). The Rd was already right (`\item{a,b}{...}`); the check compared the joined name against each formal and reported both as undocumented. A joined name also sorts at its earliest formal in `\arguments`.
* The missing-examples check runs per Rd page (#41). A function merged into a page through `@rdname` is no longer reported when another block on the page carries the examples, and a bare `@export` above an S3 method, which generates no page, is skipped.
* `check_cran()` warns when roxygen text contains markdown that ships verbatim (#42): backticked terms and `[fn()]` links, reported once per file. Example code, `@noRd` blocks, and text already inside `\code{}` are ignored. Nothing is converted. Silence it with `options(tinyrox.markdown_check = FALSE)`. The result list gains a `markdown` element.

# tinyrox 0.4.1.3

* A replacement S3 method (`$<-.myclass`, `[[<-.myclass`, `dim<-.myclass`) was given the usage `\method{$<-}{myclass}(x, name, value)`, which `R CMD check` reports as a bad `\usage` line: the `<-` sits on the generic, not at the end of the name, so the replacement test never fired. It is `\method{$}{myclass}(x, name) <- value` now, as for a plain replacement function. Found in glinty's two output-registration methods.
Expand Down
184 changes: 142 additions & 42 deletions R/cran.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ check_cran <- function(path = ".") {
code_result <- check_code_cran(path)
example_result <- check_examples_cran(path)

all_issues <- list(code = code_result, examples = example_result)
markdown_result <- check_markdown_rd(path)

has_issues <- length(code_result) > 0 || length(example_result) > 0
all_issues <- list(code = code_result, examples = example_result,
markdown = markdown_result)

has_issues <- length(code_result) > 0 || length(example_result) > 0 ||
length(markdown_result) > 0

if (!has_issues) {
message("No CRAN compliance issues found")
Expand Down Expand Up @@ -80,14 +84,16 @@ check_examples_cran <- function(path = ".") {
return(character())
}

missing_examples <- character()
# document() parses the package again and reports parse warnings
# (orphaned blocks, unknown tags) itself; repeating them here would
# only print each one twice.
blocks <- suppressWarnings(parse_package(path))
missing_examples <- suppressWarnings(find_exports_without_examples(blocks))
dontrun_fns <- character()
long_lines <- character()

for (file in r_files) {
content <- readLines(file, warn = FALSE)
file_missing <- find_exports_without_examples(content)
missing_examples <- c(missing_examples, file_missing)
file_dontrun <- find_dontrun_examples(content)
dontrun_fns <- c(dontrun_fns, file_dontrun)
file_long <- find_long_example_lines(content, basename(file))
Expand Down Expand Up @@ -119,53 +125,50 @@ check_examples_cran <- function(path = ".") {

#' Find Exported Functions Without Examples
#'
#' Parses R file content to find @export tags without @examples.
#' Examples belong to an Rd page, and blocks sharing an @rdname share one
#' page, so the check runs per topic: an exported function is reported only
#' when no block on its page carries examples. A block that generates no
#' page (a bare @export above an S3 method, or @noRd) is skipped, since
#' there is nowhere for an example to live.
#'
#' @param lines Character vector of file lines
#' @param blocks List of documentation blocks from parse_package()
#' @return Character vector of function names missing examples
find_exports_without_examples <- function(lines) {
missing <- character()
in_doc_block <- FALSE
has_export <- FALSE
has_examples <- FALSE
block_start <- 0
find_exports_without_examples <- function(blocks) {
exported <- character()
exported_topic <- character()
topics_with_examples <- character()

for (i in seq_along(lines)) {
line <- lines[i]
for (block in blocks) {
if (!block$type %in% c("function", "nn_module", "data")) {
next
}
tags <- parse_tags(block$lines, block$object, block$file, block$line)

# Start of doc block
if (grepl("^##?'", line)) {
if (!in_doc_block) {
in_doc_block <- TRUE
has_export <- FALSE
has_examples <- FALSE
block_start <- i
}
# Same page test as generate_all_rd()
if (tags$noRd ||
(is.null(tags$title) && is.null(tags$description) &&
is.null(tags$rdname))) {
next
}

# Check for export tag
if (grepl("^##?'\\s*@export", line)) {
has_export <- TRUE
}
if (!is.null(tags$rdname)) {
topic <- tags$rdname
} else {
topic <- tags$name
}

# Check for examples tag
if (grepl("^##?'\\s*@examples", line)) {
has_examples <- TRUE
}
} else if (in_doc_block) {
# End of doc block - check if it's a function definition
in_doc_block <- FALSE
if (!is.null(tags$examples) && nzchar(trimws(tags$examples))) {
topics_with_examples <- c(topics_with_examples, topic)
}

if (has_export && !has_examples) {
# Try to get function name from next non-blank line
func_name <- extract_function_name(line)
if (!is.null(func_name)) {
missing <- c(missing, func_name)
}
}
is_exported <- tags$export || !is.null(tags$exportS3Method)
if (is_exported && block$type == "function") {
exported <- c(exported, block$object)
exported_topic <- c(exported_topic, topic)
}
}

missing
exported[!exported_topic %in% topics_with_examples]
}

#' Find Exported Functions Using dontrun in Examples
Expand Down Expand Up @@ -255,6 +258,103 @@ find_long_example_lines <- function(lines, filename) {
found
}

#' Warn About Markdown That Ships Verbatim
#'
#' tinyrox does no markdown parsing, so backticked text and bracketed
#' function links written in the roxygen2 markdown habit reach the Rd
#' unchanged and render literally in help pages and the PDF manual.
#' R CMD check says nothing about them. This reports each affected file
#' once. Set options(tinyrox.markdown_check = FALSE) to silence it for a
#' package that uses backticks on purpose.
#'
#' @param path Path to package root directory
#' @return Named list, one integer vector of line numbers per affected
#' file (invisibly); empty when nothing was found or the check is off.
#' @keywords internal
check_markdown_rd <- function(path = ".") {
if (!isTRUE(getOption("tinyrox.markdown_check", TRUE))) {
return(invisible(list()))
}

r_files <- list.files(file.path(path, "R"), pattern = "\\.R$",
full.names = TRUE, ignore.case = TRUE)
found <- list()
for (file in r_files) {
hits <- find_markdown_lines(readLines(file, warn = FALSE))
if (length(hits) > 0) {
found[[basename(file)]] <- hits
}
}

if (length(found) > 0) {
report <- vapply(names(found), function(f) {
paste0(" ", f, ": ", length(found[[f]]), " line(s), first at ",
f, ":", found[[f]][1])
}, character(1))
warning("Markdown is not converted and ships verbatim in the Rd. ",
"Write \\code{x} for a backticked x and \\code{\\link{fn}} ",
"for a bracketed fn() link:\n",
paste(report, collapse = "\n"),
"\nSilence with options(tinyrox.markdown_check = FALSE).",
call. = FALSE)
}

invisible(found)
}

#' Find Documentation Lines Containing Markdown
#'
#' Flags backtick pairs and bracketed function links in documentation
#' prose. Example code is skipped (backticks are R syntax there), as are
#' blocks tagged noRd (they ship nowhere) and text already inside an Rd
#' code macro.
#'
#' @param lines Character vector of file lines
#' @return Integer vector of line numbers
#' @keywords internal
find_markdown_lines <- function(lines) {
is_doc <- grepl("^##?'", lines)
if (!any(is_doc)) {
return(integer())
}

# Consecutive doc lines form one block, as in parse_file()
block_id <- cumsum(c(TRUE, diff(is_doc) != 0))
text <- sub("^##?'\\s?", "", lines)
found <- integer()

for (id in unique(block_id[is_doc])) {
idx <- which(block_id == id)
if (any(grepl("^\\s*@noRd\\b", text[idx]))) {
next
}
in_examples <- FALSE
for (i in idx) {
tag <- regmatches(text[i], regexec("^\\s*@([a-zA-Z0-9]+)", text[i]))[[1]]
if (length(tag) == 2) {
in_examples <- tag[2] %in% c("examples", "example",
"examplesIf")
if (tag[2] %in% c("name", "rdname", "aliases",
SUPPORTED_NS_TAGS)) {
next
}
}
if (in_examples) {
next
}
# Drop spans already in an Rd code macro: \code{`[`} is correct
prose <- gsub("\\\\(code|verb|samp|preformatted|eqn|deqn)\\{[^{}]*\\}",
"", text[i])
if (grepl("`[^`]+`", prose) ||
grepl("\\[[A-Za-z0-9._:]+\\(\\)\\]", prose)) {
found <- c(found, i)
}
}
}

found
}

#' Extract Function Name from Definition Line
#'
#' @param line Code line potentially containing function definition
Expand Down
45 changes: 42 additions & 3 deletions R/namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,46 @@ generate_namespace <- function(blocks) {
if (!is.null(s3m$generic) && !is.null(s3m$class)) {
s3methods <- c(s3methods, list(list(generic = s3m$generic,
class = s3m$class)))
} else if (is.character(s3m$explicit) &&
grepl("::", s3m$explicit, fixed = TRUE)) {
# @exportS3Method pkg::generic: a method for a generic this
# package does not import. R registers it when pkg loads,
# so the directive must keep the pkg:: prefix. The class is
# the object name with "generic." removed.
prefix <- paste0(sub("^.*::", "", s3m$explicit), ".")
if (startsWith(block$object, prefix) &&
nchar(block$object) > nchar(prefix)) {
s3methods <- c(s3methods, list(list(
generic = s3m$explicit,
class = substring(block$object,
nchar(prefix) + 1L)
)))
} else {
warning("@exportS3Method ", s3m$explicit, " on ",
block$object, " at ", basename(block$file), ":",
block$line, ": the object name does not start ",
"with \"", prefix, "\", so the class is ",
"unknown; nothing was registered.", call. = FALSE)
}
} else if (!is.null(s3m$explicit)) {
# Try to parse from function name: generic.class
# Infer from the function name. A known or package-defined
# generic wins (as.data.frame.foo); otherwise split at the
# first dot.
s3_info <- detect_s3_method(block$object, pkg_generics)
parts <- strsplit(block$object, "\\.")[[1]]
if (length(parts) >= 2) {
if (!is.null(s3_info)) {
s3methods <- c(s3methods, list(s3_info))
} else if (length(parts) >= 2) {
s3methods <- c(s3methods, list(list(
generic = parts[1],
class = paste(parts[-1], collapse = ".")
)))
} else {
warning("@exportS3Method on ", block$object, " at ",
basename(block$file), ":", block$line,
" names no generic and class, and the object ",
"name has no dot to infer them from; nothing ",
"was registered.", call. = FALSE)
}
}
}
Expand Down Expand Up @@ -149,13 +181,20 @@ generate_namespace <- function(blocks) {
if (length(exports) > 0 || length(export_classes) > 0) {
lines <- c(lines, "")
}
# A block carrying both @export and @exportS3Method registers once
s3_keys <- vapply(s3methods, function(x) paste(x$generic, x$class),
character(1))
s3methods <- s3methods[!duplicated(s3_keys)]
s3methods <- s3methods[order(
vapply(s3methods, function(x) paste(x$generic, x$class), character(1))
)]
for (s3m in s3methods) {
gen <- s3m$generic
cls <- s3m$class
if (!grepl("^[a-zA-Z._][a-zA-Z0-9._]*$", gen)) {
# pkg::generic stays bare: quoted, R would look for a generic
# literally named "pkg::generic"
if (!grepl("^([a-zA-Z][a-zA-Z0-9.]*::)?[a-zA-Z._][a-zA-Z0-9._]*$",
gen)) {
gen <- paste0('"', gen, '"')
}
if (!grepl("^[a-zA-Z._][a-zA-Z0-9._]*$", cls)) {
Expand Down
Loading
Loading