Skip to content

Don't double-escape an already-escaped % in Rd output - #33

Merged
TroyHernandez merged 3 commits into
mainfrom
fix/escape-rd-double-escape
Aug 4, 2026
Merged

TroyHernandez merged 3 commits into
mainfrom
fix/escape-rd-double-escape

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

Closes #31.

Problem

escape_rd() and the three examples paths escaped % unconditionally, so a pre-escaped \% (what roxygen2 authors write, since roxygen2 makes you escape % yourself) became \\% in the generated Rd. Rd reads that as a literal backslash followed by a comment start, which swallows the rest of the line and malforms the file, with R CMD build warnings that never mention %. Hit while preparing compost for CRAN.

Fix

The five escape sites now go through one helper, escape_percent(), using the negative lookbehind from the issue: gsub("(?<!\\\\)%", "\\\\%", text, perl = TRUE). Bare % is escaped exactly once; pre-escaped \% passes through untouched. Only the already-escaped case changes; everything else stays byte-identical:

input before after
frame_%04d.png frame_\%04d.png frame_\%04d.png
frame_\%04d.png frame_\\%04d.png frame_\%04d.png
x %in% y x \%in\% y x \%in\% y
trailing \% trailing \\% trailing \%

Verification

All 230 tinytest results pass, including new regression cases covering the full behavior table, the markup-passthrough branch of escape_rd(), mixed bare and pre-escaped % in one string, and the \examples path via generate_rd(). Version bumped to 0.4.0.2.

escape_rd() and the three examples paths escaped % unconditionally, so a
pre-escaped \% from roxygen2-style sources became \\%, which Rd reads
as a literal backslash plus a comment start and mangles the generated
file with warnings that never mention %.

Centralize the escape in escape_percent(), which uses a negative
lookbehind so bare % is escaped exactly once and \% passes through
untouched. Both the bare % tinyrox always accepted and the pre-escaped
\% a roxygen2 author brings along now produce identical, valid Rd.
@TroyHernandez
TroyHernandez merged commit 7832748 into main Aug 4, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the fix/escape-rd-double-escape branch August 4, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

escape_rd() double-escapes an already-escaped % (\% -> \\%), producing malformed Rd

1 participant