fix: resolve locked namespace binding in civilytics_load_fonts() and default theme to transparent background
R-CMD-check / R CMD check (pull_request) Failing after 4m13s

- 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
This commit is contained in:
2026-08-01 02:07:09 -04:00
parent 0ef0f310e2
commit e257180f15
2 changed files with 34 additions and 19 deletions
+10 -8
View File
@@ -36,10 +36,12 @@
#' to [civilytics_colors]`["paper_2"]` (`#F2EDE4`).
#' @param grid Character. Which major gridlines to draw: `"y"` (default,
#' horizontal only), `"x"` (vertical only), `"both"`, or `"none"`.
#' @param paper_bg Logical. If `TRUE` (default), fill the plot and panel
#' backgrounds with the warm `paper` color. Set to `FALSE` for a
#' transparent background (useful for slides or overlay on colored
#' surfaces).
#' @param paper_bg Logical. If `TRUE`, fill the plot and panel backgrounds
#' with the warm `paper` color (Civilytics cream). Default is `FALSE`
#' (transparent) so that figures composite cleanly onto any background.
#' Set to `TRUE` for the branded cream canvas. Note: a transparent device
#' background (e.g., `dev = "ragg_png"`, `dev.args = list(background =
#' "transparent")`) is also needed for fully-transparent PNG exports.
#'
#' @section Font size hierarchy:
#' All text sizes are derived from `font_size` using relative scale factors.
@@ -68,7 +70,7 @@
#' \dontrun{
#' library(ggplot2)
#'
#' # Default editorial theme
#' # Default — transparent background for embedding
#' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() +
#' theme_civilytics()
@@ -79,10 +81,10 @@
#' scale_color_civilytics() +
#' theme_civilytics(grid = "both")
#'
#' # Transparent background for embedding
#' # Branded cream background (opt-in)
#' ggplot(mpg, aes(displ, hwy)) +
#' geom_point() +
#' theme_civilytics(paper_bg = FALSE)
#' theme_civilytics(paper_bg = TRUE)
#'
#' # Larger text for poster or display
#' ggplot(mpg, aes(displ, hwy)) +
@@ -102,7 +104,7 @@ theme_civilytics <- function(
accent = unname(civilytics_colors["ember_600"]),
strip_color = unname(civilytics_colors["paper_2"]),
grid = c("y", "x", "both", "none"),
paper_bg = TRUE) {
paper_bg = FALSE) {
grid <- match.arg(grid)
half_line <- font_size / 2