feat(flextable): reusable Civilytics flextable branding helpers #10
Merged
jared
merged 1 commits from 2026-06-22 17:00:09 -04:00
feat/flextable-branding into feat/stamp-logo-png
No Reviewers
Labels
Clear labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
kodor
kodor/feature-proposal
kodor/fix
kodor/needs-review
kodor/triaged
question
wontfix
kodor
kodor/feature-proposal
kodor/fix
kodor/needs-review
kodor/triaged
Something isn't working
Improvements or additions to documentation
This issue or pull request already exists
New feature or request
Good for newcomers
Extra attention is needed
This doesn't seem right
Kodor should process this issue
Kodor has written a feature proposal
Kodor should implement a fix (assigned to Kodor)
Kodor's work or failure needs Jared's review
Kodor has already triaged this issue (skip)
Further information is requested
This will not be worked on
needs
human
Cannot move without a person -- a decision, a check an agent cannot make, something outside the repo
origin
client
Came from a client ask
origin
obligation
Created by a change elsewhere
origin
review
Came from human review
origin
roborev
Promoted from a roborev finding
type
chore
Maintenance with no behaviour change
type
debt
Owed work -- docs, tests, cleanup a change obligated
type
decision
Needs a decision before work can proceed
type
defect
Something is wrong
type
feature
New capability
ws
helpers
Analysis and workflow helpers
ws
logo
Logo and branded output composition
ws
packaging
Package infrastructure and release
ws
quarto
Quarto themes and publishing templates
ws
theme
Themes, palettes, and fonts
Assign a task to kodor
Kodor thinks this needs a feature.
Kodor should fix this
Kodor thinks the user is ready to review this.
Kodor is done with this issue.
No labels
Milestone
No items
No Milestone
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Civilytics/civilyticsR#10
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Stacked on #9
This PR is stacked on #9 (
feat/stamp-logo-png), becausesave_branded_flextable_png()callsstamp_logo_png(), which only exists on that branch. Retarget this PR tomasteronce #9 merges.What this adds
Two small, reusable functions in new file
R/flextable.Rthat generalize the flextable brand styling + "export to PNG + stamp logo" dance repeated across Civilytics projects:style_flextable_civilytics(ft, ...)— applies only the visual brand to an already-structured flextable: header fill#2c3e50/ white bold text / 14pt title line, 11pt Arial body, zebra striping on even body rows (#f0f0eb, guarded for tables with < 2 rows), outer#888888+ inner-horizontal#ccccccborders, footer 9pt#555555(only if a footer part exists), andlayout = "fixed". Every value is an overridable parameter;zebra = TRUEtoggles striping. Scope discipline: structure (labels, header lines, widths, alignment, footer text) stays with the caller — this styles only.save_branded_flextable_png(ft, path, logo = TRUE, res = 300, extra_height = 0.4, ...)— sizes aragg::agg_png()device toflextable_dim(ft)plusextra_heightheadroom,plot(ft), closes the device, then (iflogo) callsstamp_logo_png(path, ...)with...forwardingtype/variant/position/etc. Returnspathinvisibly.Intended caller usage (callers not changed here)
Suggests-guard design
flextable,officer, andraggare added to Suggests (not Imports) to keep the base install light. Accordingly, no@importFromfor them — everything is referenced fully qualified (flextable::,officer::,ragg::) and each function guards at the top withrequireNamespace(..., quietly = TRUE)+ an install hint.stamp_logo_png()is in-package (called directly);grDevicesis base.Test evidence
tests/testthat/test_flextable.R— real round-trip tests (not skip-only; guarded withskip_if_not_installed()for portability, basetempfile()+on.exit(unlink())):style_flextable_civilytics()returns aflextableand yieldslayout = "fixed"zebra = FALSEstill validsave_branded_flextable_png()writes a PNG with plausible pixel dimensionslogo = FALSEskips stamping but still writesextra_heightproduces a taller PNG(Warnings are harmless Arial font-substitution messages from headless rendering.)
Files changed
R/flextable.R,man/style_flextable_civilytics.Rd,man/save_branded_flextable_png.Rd,tests/testthat/test_flextable.R,DESCRIPTION(Suggests),NAMESPACE(two exports). Pre-existing roxygen doc drift in the repo was reverted to keep this PR focused.