fix: resolve locked namespace binding in civilytics_load_fonts() and default theme to transparent background #19

Merged
jared merged 3 commits from kodor/fix-18-fonts-and-theme into master 2026-08-03 10:46:41 -04:00
Member

Summary

Fixes two issues in the civilyticsR package:

#18 - locked namespace binding error in civilytics_load_fonts()

Problem: The function used <<- to write to a package-level variable (.cv_fonts_loaded), which R locks when the namespace seals at load time. This caused an error on every call: cannot change value of locked binding for .cv_fonts_loaded.

Fix: Replaced the plain variable with a mutable environment (.cv_state) whose contents remain writable even though the binding itself is locked. This follows the standard R idiom for mutable package state (see Advanced R: Environments as containers).

Additional: Added a force = FALSE argument so subsequent calls within the same session are no-ops (the guard flag now actually works).

#7 - Default theme_civilytics() to transparent background

Problem: The cream paper background (#FAF7F2) was the default, forcing downstream consumers to override it for transparent figures.

Fix: Flipped paper_bg default from TRUE to FALSE. Cream is now an explicit opt-in via theme_civilytics(paper_bg = TRUE).

Breaking change note: Existing code relying on the cream default will now get transparent backgrounds. Add paper_bg = TRUE to restore the previous behavior.

Files changed

  • R/fonts.R - Environment-based state, guard check, updated roxygen
  • R/theme.R - Default flip, updated docs and examples

Testing

Changes follow standard R patterns. Manual testing requires an R session with the civilytics package installed.

## Summary Fixes two issues in the civilyticsR package: ### #18 - locked namespace binding error in civilytics_load_fonts() Problem: The function used <<\- to write to a package-level variable (.cv_fonts_loaded), which R locks when the namespace seals at load time. This caused an error on every call: cannot change value of locked binding for .cv_fonts_loaded. Fix: Replaced the plain variable with a mutable environment (.cv_state) whose contents remain writable even though the binding itself is locked. This follows the standard R idiom for mutable package state (see Advanced R: Environments as containers). Additional: Added a force = FALSE argument so subsequent calls within the same session are no-ops (the guard flag now actually works). ### #7 - Default theme_civilytics() to transparent background Problem: The cream paper background (#FAF7F2) was the default, forcing downstream consumers to override it for transparent figures. Fix: Flipped paper_bg default from TRUE to FALSE. Cream is now an explicit opt-in via theme_civilytics(paper_bg = TRUE). Breaking change note: Existing code relying on the cream default will now get transparent backgrounds. Add paper_bg = TRUE to restore the previous behavior. ## Files changed - R/fonts.R - Environment-based state, guard check, updated roxygen - R/theme.R - Default flip, updated docs and examples ## Testing Changes follow standard R patterns. Manual testing requires an R session with the civilytics package installed.
kodor added 1 commit 2026-08-01 02:09:30 -04:00
- Replace .cv_fonts_loaded <<- TRUE with environment-based state
  (.cv_state) to avoid 'locked namespace binding' error (#18)
- Add force=FALSE argument for idempotent font loading with guard check
- Flip theme_civilytics() paper_bg default to FALSE (transparent) (#7)
- Update roxygen docs and examples for both changes
kodor added 1 commit 2026-08-01 21:30:08 -04:00
fix(test): update theme tests for paper_bg=FALSE default (#19)
R-CMD-check / R CMD check (pull_request) Failing after 5m47s
f32093c662
kodor added 1 commit 2026-08-01 21:45:00 -04:00
docs: regenerate roxygen documentation for paper_bg and force params (#19)
R-CMD-check / R CMD check (pull_request) Successful in 4m29s
967e7e1111
jared merged commit 9dea017381 into master 2026-08-03 10:46:41 -04:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Civilytics/civilyticsR#19