diff --git a/DESCRIPTION b/DESCRIPTION index 0e36aa5..eb76ff3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: tinyrox Title: Minimal R Documentation Generator -Version: 0.4.1.1 -Date: 2026-08-04 +Version: 0.4.1.2 +Date: 2026-08-31 Authors@R: c( person("Troy", "Hernandez", email = "troy@cornball.ai", role = c("aut", "cre"), comment = c(ORCID = "0009-0005-4248-604X")), diff --git a/NEWS.md b/NEWS.md index 250cba3..c7145e8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# tinyrox 0.4.1.2 + +* Datasets are documented. A block over a bare `"name"` line (the roxygen data convention) used to be dropped silently: no Rd, no warning, and `R CMD check` then reported the dataset undocumented. The directive now parses like the `"_PACKAGE"` sentinel, `@format` and `@source` are supported tags (an author's `@format` wins over the auto-introspected one), and data pages carry `\source{}`. Found standing up examen's `are` dataset. + # tinyrox 0.4.1.1 * Rd file names are portable for every topic, not just `%op%` and a leading dot. `$.foo`, `[[.foo` and `$<-.foo` are ordinary S3 methods, and the files named after them were being **dropped from the tarball**: `R CMD build` prints "excluding invalid files" and carries on, and the `R CMD check` that follows reads a tarball those files are no longer in, so nothing fails. glinty shipped four undocumented S3 methods that way with every CI job green. diff --git a/R/parse.R b/R/parse.R index 716d304..a4031d7 100644 --- a/R/parse.R +++ b/R/parse.R @@ -146,6 +146,16 @@ parse_object_definition <- function(text, file, line_num) { return(list(name = "_PACKAGE", type = "package", formals = NULL)) } + # Quoted-string directive: a bare "name" (or 'name') line after the + # block documents the dataset `name` (the roxygen convention for + # data documentation). Without this the block is dropped silently, + # since a string literal matches no assignment pattern below. + fl <- trimws(first_line) + if (grepl('^"[^"]+"$', fl) || grepl("^'[^']+'$", fl)) { + return(list(name = substr(fl, 2L, nchar(fl) - 1L), type = "data", + formals = NULL)) + } + # Match: name <- or name = # Handles: foo <- function(...), foo <- value, foo = function(...) # Also handles backtick-quoted names: `%||%` <- function(...) diff --git a/R/rd.R b/R/rd.R index 9365080..87f6765 100644 --- a/R/rd.R +++ b/R/rd.R @@ -194,10 +194,16 @@ generate_data_rd <- function(tags, source_file = NULL, format_string = NULL) { } lines <- c(lines, paste0("\\title{", escape_rd(title), "}")) - # Format section (roxygen2 auto-generates this) - if (!is.null(format_string)) { + # Format section: an author's @format wins; otherwise fall back to + # the auto-generated description of the object (roxygen2 behavior) + if (!is.null(tags$format)) { + fmt <- escape_rd(tags$format) + } else { + fmt <- format_string + } + if (!is.null(fmt)) { lines <- c(lines, "\\format{") - lines <- c(lines, format_string) + lines <- c(lines, fmt) lines <- c(lines, "}") } @@ -226,6 +232,13 @@ generate_data_rd <- function(tags, source_file = NULL, format_string = NULL) { lines <- c(lines, "}") } + # Source (where the data came from) + if (!is.null(tags$source)) { + lines <- c(lines, "\\source{") + lines <- c(lines, escape_rd(tags$source)) + lines <- c(lines, "}") + } + # Examples (before seealso like roxygen2) if (!is.null(tags$examples) && nchar(trimws(tags$examples)) > 0) { lines <- c(lines, "\\examples{") diff --git a/R/tags.R b/R/tags.R index 7388f94..ebc30bf 100644 --- a/R/tags.R +++ b/R/tags.R @@ -5,7 +5,8 @@ SUPPORTED_DOC_TAGS <- c("title", "description", "details", "param", "return", "returns", "value", "examples", "example", "seealso", "references", "aliases", "keywords", "family", "name", "rdname", "noRd", - "inheritParams", "section", "author") + "inheritParams", "section", "author", "format", + "source") #' Supported Namespace Tags #' @@ -227,6 +228,12 @@ save_tag <- function(result, tag, arg, accumulator, file, line_num) { }, "references" = { result$references <- value + }, + "format" = { + result$format <- value + }, + "source" = { + result$source <- value }, "aliases" = { # Split on whitespace diff --git a/inst/tinytest/test_parse.R b/inst/tinytest/test_parse.R index d1b01c8..7d3eca8 100644 --- a/inst/tinytest/test_parse.R +++ b/inst/tinytest/test_parse.R @@ -140,3 +140,28 @@ expect_warning(blocks <- tinyrox:::parse_file(tmp), expect_equal(length(blocks), 1) expect_equal(blocks[[1]]$object, "real_fn") unlink(tmp) + +# Quoted-string data directive: a block over a bare "name" line documents +# the dataset `name` (roxygen convention). Both quote styles; the +# _PACKAGE sentinel keeps its own type and must not be shadowed. +tmp <- tempfile(fileext = ".R") +writeLines(c( + "#' My dataset", + "#'", + "#' @format A data frame.", + "\"mydata\"", + "", + "#' Single-quoted dataset", + "'otherdata'", + "", + "#' The package", + "\"_PACKAGE\"" +), tmp) +blocks <- tinyrox:::parse_file(tmp) +expect_equal(length(blocks), 3) +expect_equal(blocks[[1]]$object, "mydata") +expect_equal(blocks[[1]]$type, "data") +expect_equal(blocks[[2]]$object, "otherdata") +expect_equal(blocks[[2]]$type, "data") +expect_equal(blocks[[3]]$type, "package") +unlink(tmp) diff --git a/inst/tinytest/test_rd.R b/inst/tinytest/test_rd.R index fff1951..bd894d2 100644 --- a/inst/tinytest/test_rd.R +++ b/inst/tinytest/test_rd.R @@ -395,3 +395,54 @@ test_package_sentinel_document <- function() { expect_equal(res2$pruned, character(0)) } test_package_sentinel_document() + +# --- Data documentation through the full document() flow: the "name" --- +# directive plus @format and @source. Regression: the block used to be +# dropped silently (no Rd, no warning), leaving the dataset undocumented. +test_data_directive_document <- function() { + pkg <- file.path(tempdir(), "datapkg") + on.exit(unlink(pkg, recursive = TRUE), add = TRUE) + dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE) + writeLines(c( + "Package: datapkg", "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( + "#' Example measurements", + "#'", + "#' Twelve made-up observations.", + "#'", + "#' @format A data frame with 12 rows and 2 columns:", + "#' \\describe{", + "#' \\item{x}{Numeric. The measurement.}", + "#' \\item{g}{Character. The group.}", + "#' }", + "#' @source Simulated for the test.", + "#' @examples", + "#' str(measurements)", + "\"measurements\""), + file.path(pkg, "R", "data.R")) + + # No warnings: @format and @source are supported tags, not unknowns. + expect_silent(tinyrox::document(pkg, cran_check = FALSE, silent = TRUE)) + + rd_path <- file.path(pkg, "man", "measurements.Rd") + expect_true(file.exists(rd_path)) + rd <- readLines(rd_path) + expect_true("\\docType{data}" %in% rd) + expect_true("\\alias{measurements}" %in% rd) + expect_true("\\keyword{datasets}" %in% rd) + # The author's @format survives, markup intact, over the auto fallback + expect_true(any(grepl("12 rows and 2 columns", rd))) + expect_true(any(grepl("\\item{x}{Numeric. The measurement.}", rd, + fixed = TRUE))) + # @source is rendered + expect_true("\\source{" %in% rd) + expect_true(any(grepl("Simulated for the test.", rd, fixed = TRUE))) + # Usage is the bare object name, and the dataset is not exported + expect_true("measurements" %in% rd) + ns <- readLines(file.path(pkg, "NAMESPACE")) + expect_false(any(grepl("measurements", ns, fixed = TRUE))) +} +test_data_directive_document() diff --git a/man/SUPPORTED_DOC_TAGS.Rd b/man/SUPPORTED_DOC_TAGS.Rd index 90b3604..43d1cca 100644 --- a/man/SUPPORTED_DOC_TAGS.Rd +++ b/man/SUPPORTED_DOC_TAGS.Rd @@ -4,7 +4,7 @@ \alias{SUPPORTED_DOC_TAGS} \title{Supported Documentation Tags} \format{ -An object of class \code{character} of length 20. +An object of class \code{character} of length 22. } \usage{ SUPPORTED_DOC_TAGS diff --git a/man/SUPPORTED_TAGS.Rd b/man/SUPPORTED_TAGS.Rd index ba88416..898dc8c 100644 --- a/man/SUPPORTED_TAGS.Rd +++ b/man/SUPPORTED_TAGS.Rd @@ -4,7 +4,7 @@ \alias{SUPPORTED_TAGS} \title{All Supported Tags} \format{ -An object of class \code{character} of length 26. +An object of class \code{character} of length 28. } \usage{ SUPPORTED_TAGS