Treat a single NA as NULL for export_tfl_page annotations#42
Merged
Conversation
A single NA supplied for an annotation or presence-toggle argument in export_tfl_page() now behaves exactly like NULL (the "absent" state), so data-driven page construction can pass NA for an unsupplied value instead of rendering the literal text "NA" or erroring. Covered arguments: caption, footnote, header_left/center/right, footer_left/center/right (section element absent), page_i (no "Page <i>: " error prefix), and header_rule/footer_rule (no rule, i.e. FALSE). Implemented once via a shared predicate .is_single_na() in R/normalize.R, consumed by normalize_text(), normalize_rule(), and a page_i coercion in export_tfl_page(). Because annotations flow through normalize_text() after the x[[key]] override merge, a per-page x$caption = NA also blanks an otherwise-global caption. Only a single NA is absent; a longer vector with NA among real values is collapsed with "\n" as before. Enumerated settings validated by match.arg (caption_just, footnote_just, content_just, overflow_action) and unit args (padding, margins, min_content_height) deliberately still error on NA (fail-loud). Rationale in design/DECISIONS.md as D-52. Tests assert via a display-list label sweep that no literal "NA" reaches the page for any annotation, plus the page_i and rule cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reverts the premature NEWS entry; NEWS tracking starts once the package version exceeds 0.0.1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A single
NAsupplied for an annotation or presence-toggle argument inexport_tfl_page()now behaves exactly likeNULL(the "absent" state), so data-driven page construction (one row per page) can passNAfor an unsupplied value instead of rendering the literal text"NA"or erroring.Covered arguments:
NAbehaviorcaption,footnote,header_left/center/right,footer_left/center/rightNULL)page_i"Page <i>: "error prefixheader_rule,footer_ruleFALSE)How
Implemented once via a shared predicate
.is_single_na()inR/normalize.R(length-1 atomicNAof any type), consumed bynormalize_text(),normalize_rule(), and apage_icoercion inexport_tfl_page().Because annotations flow through
normalize_text()after thex[[key]]override merge, a per-pagex$caption = NAnow also blanks an otherwise-global caption. Only a singleNAis absent — a longer vector withNAamong real values (c("a", NA, "b")) is still collapsed with"\n"as before, so multi-line content is never silently dropped.Considered but deliberately left to fail loudly
padding,margins,min_content_height—unitobjects;NAis malformed, caught bycheckmate.caption_just,footnote_just,content_just,overflow_action— enumeratedmatch.argsettings with concrete defaults; anNAsignals a construction bug and should error.gp,preview,newpage,x— not presence toggles.Rationale recorded as D-52 in
design/DECISIONS.md.Tests
test-normalize.R:.is_single_na()truth table,normalize_text(NA)across atomic types, the multi-element-NAboundary,normalize_rule(NA).test-export_tfl_page.R: agrid.grab()display-list label sweep asserting no literal"NA"reaches the page for each of the 8 annotations, all-NArenders identically to none-supplied, thex-override blanking case,page_i = NA, andheader_rule/footer_rule = NA(previously threw). These fail against the pre-fix code.Full test suite passes. Docs regenerated via roxygen;
CLAUDE.mdand alldesign/docs updated.🤖 Generated with Claude Code