Skip to content

Treat a single NA as NULL for export_tfl_page annotations#42

Merged
billdenney merged 3 commits into
mainfrom
claude/export-tfl-page-na-null-1a2f5f
Jul 8, 2026
Merged

Treat a single NA as NULL for export_tfl_page annotations#42
billdenney merged 3 commits into
mainfrom
claude/export-tfl-page-na-null-1a2f5f

Conversation

@billdenney

Copy link
Copy Markdown
Member

What

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 (one row per page) can pass NA for an unsupplied value instead of rendering the literal text "NA" or erroring.

Covered arguments:

Argument(s) NA behavior
caption, footnote, header_left/center/right, footer_left/center/right section element absent (identical to NULL)
page_i no "Page <i>: " error prefix
header_rule, footer_rule no rule (FALSE)

How

Implemented once via a shared predicate .is_single_na() in R/normalize.R (length-1 atomic NA of any type), 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 now also blanks an otherwise-global caption. Only a single NA is absent — a longer vector with NA among 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_heightunit objects; NA is malformed, caught by checkmate.
  • caption_just, footnote_just, content_just, overflow_action — enumerated match.arg settings with concrete defaults; an NA signals 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-NA boundary, normalize_rule(NA).
  • test-export_tfl_page.R: a grid.grab() display-list label sweep asserting no literal "NA" reaches the page for each of the 8 annotations, all-NA renders identically to none-supplied, the x-override blanking case, page_i = NA, and header_rule/footer_rule = NA (previously threw). These fail against the pre-fix code.

Full test suite passes. Docs regenerated via roxygen; CLAUDE.md and all design/ docs updated.

🤖 Generated with Claude Code

billdenney and others added 3 commits July 8, 2026 19:05
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>
@billdenney
billdenney merged commit e6bf8df into main Jul 8, 2026
9 checks passed
@billdenney
billdenney deleted the claude/export-tfl-page-na-null-1a2f5f branch July 8, 2026 23:45
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.

1 participant