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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tinyrox
Title: Minimal R Documentation Generator
Version: 0.4.1
Version: 0.4.1.1
Date: 2026-08-04
Authors@R: c(
person("Troy", "Hernandez", email = "troy@cornball.ai", role = c("aut", "cre"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 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.
* The substitution table is roxygen2's, so a package moving between the two tools does not churn its `man` directory, and the two cases tinyrox already handled (`%||%`, a leading dot) come out spelled exactly as before. `document()` now refuses outright if a name it wrote would still be dropped.

# tinyrox 0.4.1

Two Rd-generation fixes.
Expand Down
1 change: 1 addition & 0 deletions R/document.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ document <- function(path = ".",
message("Generating Rd files...")
}
rd_files <- generate_all_rd(blocks, path, cran_check)
check_rd_filenames(rd_files)
if (!silent) {
message("Generated ", length(rd_files), " Rd file(s).")
}
Expand Down
106 changes: 77 additions & 29 deletions R/rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -510,41 +510,89 @@ write_rd <- function(content, name, path = ".") {
dir.create(man_dir, recursive = TRUE)
}

# Sanitize filename for Rd (like roxygen2)
# - Internal functions starting with . -> dot-name
# - Infix operators %X% -> grapes-X-grapes
filename <- name
if (grepl("^\\.", filename)) {
filename <- gsub("^\\.", "dot-", filename)
} else if (grepl("^%.*%$", filename)) {
# Encode infix operator: %||% -> grapes-or-or-grapes
# Only encode special characters, keep alphanumeric sequences intact
inner <- gsub("^%|%$", "", filename)
# Replace special characters with _WORD_ markers first
inner <- gsub("\\|", "_OR_", inner)
inner <- gsub("&", "_AND_", inner)
inner <- gsub("\\+", "_PLUS_", inner)
inner <- gsub("-", "_MINUS_", inner)
inner <- gsub("\\*", "_TIMES_", inner)
inner <- gsub("/", "_DIV_", inner)
inner <- gsub("<", "_LT_", inner)
inner <- gsub(">", "_GT_", inner)
inner <- gsub("=", "_EQ_", inner)
inner <- gsub("!", "_NOT_", inner)
# Convert markers to lowercase with - separators
inner <- gsub("_([A-Z]+)_", "-\\L\\1-", inner, perl = TRUE)
# Clean up multiple - and leading/trailing -
inner <- gsub("-+", "-", inner)
inner <- gsub("^-|-$", "", inner)
filename <- paste0("grapes-", inner, "-grapes")
}
filepath <- file.path(man_dir, paste0(filename, ".Rd"))
filepath <- file.path(man_dir, paste0(rd_filename(name), ".Rd"))

writeLines(content, filepath, useBytes = TRUE)

filepath
}

#' Refuse to Leave a File Name R CMD build Will Drop
#'
#' rd_filename() is supposed to make every name portable. This says so
#' out loud rather than trusting it, because the failure is silent in
#' both directions: `R CMD build` drops the file without an error, and
#' the `R CMD check` that follows examines a tarball the file is no
#' longer in.
#'
#' @param files Character vector of paths just written.
#' @return invisible(TRUE)
#' @keywords internal
check_rd_filenames <- function(files) {
bad <- basename(files)[!grepl("^[A-Za-z0-9._-]+$", basename(files))]
if (length(bad) > 0) {
stop("these Rd file names are not portable, and R CMD build would ",
"drop them from the tarball without failing: ",
paste(bad, collapse = ", "), call. = FALSE)
}
invisible(TRUE)
}

#' What a Topic Is Called on Disk
#'
#' Replacements applied to a topic name to make a file name, longest
#' key first so `[<-` is read before `[`. This is the table roxygen2
#' uses, so a package moving between the two does not churn its `man`
#' directory, and the two names tinyrox already handled -- `%||%` and
#' a leading dot -- come out exactly as they did.
#'
#' @keywords internal
RD_NAME_SUBS <- c("[<-" = "-subset-", "[" = "-sub-", "<-" = "-set-",
"::" = "-", "!" = "-not-", "&" = "-and-", "|" = "-or-",
"*" = "-times-", "+" = "-plus-", "^" = "-pow-",
"\"" = "-quote-", "#" = "-hash-", "$" = "-cash-",
"%" = "-grapes-", "'" = "-single-quote-",
"(" = "-open-paren-", ")" = "-close-paren-",
":" = "-colon-", ";" = "-semi-colon-", "<" = "-less-than-",
"==" = "-equals-", "=" = "-equals-",
">" = "-greater-than-", "?" = "-help-", "@" = "-at-",
"]" = "-close-brace-", "\\" = "-backslash-",
"/" = "-slash-", "`" = "-tick-", "{" = "-open-curly-",
"}" = "-close-", "~" = "-twiddle-")

#' Turn a Topic Name into a Portable File Name
#'
#' A topic can be called anything R can name, and `$.foo`, `[[.foo`
#' and `$<-.foo` are ordinary S3 methods. Those characters are not
#' legal in a file name on every platform R runs on, and `R CMD build`
#' does not warn and carry on: it prints "excluding invalid files" and
#' **drops them from the tarball**. The package then installs with no
#' documentation for those methods, and `R CMD check` reports nothing,
#' because it checks the tarball the files are no longer in. Green,
#' and missing its docs.
#'
#' The `\\name{}` inside the file keeps the real topic, so help still
#' resolves under it; only the file on disk is renamed.
#'
#' @param name Topic name.
#' @return A file name stem, with no .Rd extension.
#' @keywords internal
rd_filename <- function(name) {
out <- name
for (i in seq_along(RD_NAME_SUBS)) {
out <- gsub(names(RD_NAME_SUBS)[[i]], RD_NAME_SUBS[[i]], out,
fixed = TRUE)
}
# Anything still outside the portable set becomes a separator
# rather than being left to break the build later.
out <- gsub("[^A-Za-z0-9_.-]+", "-", out)
out <- gsub("-+", "-", out)
out <- gsub("^-|-$", "", out)
# A leading dot hides the file on unix and is dropped by some
# archivers; .onLoad and friends are ordinary topics.
gsub("^\\.", "dot-", out)
}

#' Identify a tinyrox-Generated Rd File
#'
#' Returns TRUE only if the file's first line is exactly RD_MARKER. This is
Expand Down
81 changes: 81 additions & 0 deletions inst/tinytest/test_rd_filenames.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# What a topic is called on disk.
#
# A topic can be called anything R can name, and `$.foo`, `[[.foo` and
# `$<-.foo` are ordinary S3 methods. Those characters are not legal in
# a file name everywhere R runs, and R CMD build does not warn and
# carry on -- it prints "excluding invalid files" and drops them from
# the tarball. The package installs with no docs for those methods,
# and R CMD check reports nothing, because it checks the tarball the
# files are no longer in.
#
# glinty shipped four undocumented S3 methods that way.

rd_filename <- tinyrox:::rd_filename
check_rd_filenames <- tinyrox:::check_rd_filenames

# --- the four that were being dropped ---
expect_equal(rd_filename("$.glinty_input"), "cash-.glinty_input")
expect_equal(rd_filename("[[.glinty_input"), "sub-sub-.glinty_input")
expect_equal(rd_filename("$<-.glinty_output"), "cash-set-.glinty_output")
expect_equal(rd_filename("[[<-.glinty_output"), "sub-subset-.glinty_output")

# --- what tinyrox already handled keeps its old name ---
#
# The table is roxygen2's, and these two come out of it unchanged, so
# adopting it renames nothing that was already working.
expect_equal(rd_filename("%||%"), "grapes-or-or-grapes")
expect_equal(rd_filename(".hidden"), "dot-hidden")
expect_equal(rd_filename(".onLoad"), "dot-onLoad")

# --- ordinary names are left alone ---
for (name in c("document", "write_rd", "run_app", "as.character.foo",
"x2", "a.b.c", "with_underscores_and.dots")) {
expect_equal(rd_filename(name), name, info = name)
}

# --- the rest of the operators ---
expect_equal(rd_filename("+.difftime"), "plus-.difftime")
expect_equal(rd_filename("[.data.frame"), "sub-.data.frame")
expect_equal(rd_filename("<-.foo"), "set-.foo")
expect_equal(rd_filename("=="), "equals")
expect_equal(rd_filename("!.foo"), "not-.foo")

# --- every result is portable, whatever went in ---
#
# The point is not the spelling, it is that nothing reaches disk that
# the build would throw away.
awkward <- c("$.a", "[[.b", "[<-.c", "%in%", "?.d", "@.e", "/.f", "\\.g",
"{.h", "~.i", "|.j", "&.k", "*.l", "^.m", "#.n", "`.o",
";.p", "(.q", ").r", "<.s", ">.t", ":.u", "::v", "'.w",
"\".x", "}.y", "].z")
for (name in awkward) {
out <- rd_filename(name)
expect_true(grepl("^[A-Za-z0-9._-]+$", out),
info = paste(name, "->", out))
# no leading dot, no doubled or dangling separators
expect_false(startsWith(out, "."), info = out)
expect_false(grepl("--", out, fixed = TRUE), info = out)
expect_false(startsWith(out, "-") || endsWith(out, "-"), info = out)
}

# and distinct topics stay distinct, or one would overwrite the other
expect_equal(anyDuplicated(vapply(awkward, rd_filename, character(1))), 0L)

# --- the guard ---
expect_true(check_rd_filenames(c("man/ok.Rd", "man/also-ok.Rd")))
expect_error(check_rd_filenames("man/$.foo.Rd"), pattern = "not portable")
expect_error(check_rd_filenames(c("man/fine.Rd", "man/[[.bar.Rd")),
pattern = "drop them from the tarball")
expect_true(check_rd_filenames(character(0)))

# --- end to end: a package with these methods builds with them ---
#
# Writing the file is the half that used to work. This checks the half
# that did not: that the name it lands under survives R CMD build.
pkg <- file.path(tempdir(), "rdnames")
dir.create(file.path(pkg, "man"), recursive = TRUE, showWarnings = FALSE)
written <- tinyrox:::write_rd("\\name{$.foo}\n\\title{x}\n", "$.foo", pkg)
expect_true(file.exists(written))
expect_equal(basename(written), "cash-.foo.Rd")
expect_true(grepl("^[A-Za-z0-9._-]+$", basename(written)))
unlink(pkg, recursive = TRUE)
19 changes: 19 additions & 0 deletions man/RD_NAME_SUBS.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
% tinyrox says don't edit this manually, but it can't stop you!
\docType{data}
\name{RD_NAME_SUBS}
\alias{RD_NAME_SUBS}
\title{What a Topic Is Called on Disk}
\format{
An object of class \code{character} of length 32.
}
\usage{
RD_NAME_SUBS
}
\description{
Replacements applied to a topic name to make a file name, longest
key first so `[<-` is read before `[`. This is the table roxygen2
uses, so a package moving between the two does not churn its `man`
directory, and the two names tinyrox already handled -- `\%||\%` and
a leading dot -- come out exactly as they did.
}
\keyword{internal}
21 changes: 21 additions & 0 deletions man/check_rd_filenames.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% tinyrox says don't edit this manually, but it can't stop you!
\name{check_rd_filenames}
\alias{check_rd_filenames}
\title{Refuse to Leave a File Name R CMD build Will Drop}
\usage{
check_rd_filenames(files)
}
\arguments{
\item{files}{Character vector of paths just written.}
}
\value{
invisible(TRUE)
}
\description{
rd_filename() is supposed to make every name portable. This says so
out loud rather than trusting it, because the failure is silent in
both directions: `R CMD build` drops the file without an error, and
the `R CMD check` that follows examines a tarball the file is no
longer in.
}
\keyword{internal}
29 changes: 29 additions & 0 deletions man/rd_filename.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
% tinyrox says don't edit this manually, but it can't stop you!
\name{rd_filename}
\alias{rd_filename}
\title{Turn a Topic Name into a Portable File Name}
\usage{
rd_filename(name)
}
\arguments{
\item{name}{Topic name.}
}
\value{
A file name stem, with no .Rd extension.
}
\description{
A topic can be called anything R can name, and `$.foo`, `[[.foo`
and `$<-.foo` are ordinary S3 methods. Those characters are not
legal in a file name on every platform R runs on, and `R CMD build`
does not warn and carry on: it prints "excluding invalid files" and
**drops them from the tarball**. The package then installs with no
documentation for those methods, and `R CMD check` reports nothing,
because it checks the tarball the files are no longer in. Green,
and missing its docs.
}
\details{
The `\\name{}` inside the file keeps the real topic, so help still
resolves under it; only the file on disk is renamed.

}
\keyword{internal}
Loading