Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Two regional reporting vignettes in `vignettes/`:

Both share the same structure (Area of Interest → Trends → Snowpack → Spatial Pattern → Per-Ecoregion → WSGs Across Ecoregions → Interpretation). Heavy data is precomputed by `data-raw/<vignette>_vignette_data.R` into `inst/vignette-data/<vignette>.{rds,tif}` so pkgdown CI doesn't re-fetch from S3 on every render. ASWS QA cross-checks are in `data-raw/qa_snow_validation*.R` — run locally only, results land in `planning/archive/<issue>/`.

**Bibliography regen.** After adding or removing `[@key]` markers in either vignette, regenerate `vignettes/references.bib` from Zotero/BBT by running `Rscript data-raw/regenerate_bib.R`. Pulls source records via rbbt → BBT, writes the union of keys across both vignettes. Requires Zotero running with BBT enabled (BBT 9.x for Zotero 8/9). CI does not run this — the bib is committed and pkgdown reads the static file.

The two-vignette template is the foundation for additional regional reporting appendices (cf #47) — port directly to a `fish_passage_<region>_<year>` reporting context.

## Data Directories (gitignored)
Expand Down
66 changes: 66 additions & 0 deletions data-raw/regenerate_bib.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env Rscript
#
# data-raw/regenerate_bib.R
#
# Regenerate vignettes/references.bib from the union of [@key] markers
# used in the regional vignettes (kootenay-lake.Rmd, peace-fwcp.Rmd).
# Pulls source records from Zotero via Better BibTeX (rbbt → BBT).
#
# Run after adding/removing [@key] markers in either vignette:
# Rscript data-raw/regenerate_bib.R
#
# Prerequisites:
# - Zotero desktop running with BBT plugin enabled
# BBT 9.x for Zotero 8/9; BBT 8.x for Zotero 7
# (if BBT shows "disabled by Zotero" in the plugin manager,
# reinstall the matching version per soul#43)
# - All [@key] markers in either vignette must resolve to items
# in the NewGraphEnvironment Zotero library
#
# CI does not run this script — vignettes/references.bib is committed
# and pkgdown reads the static file. Re-run + commit whenever cites
# change. Keys not used in the vignettes are dropped automatically.

vignettes <- c(
here::here("vignettes", "kootenay-lake.Rmd"),
here::here("vignettes", "peace-fwcp.Rmd")
)
out_path <- here::here("vignettes", "references.bib")

# --- Detect citation keys per vignette ---
keys_per_rmd <- lapply(vignettes, function(rmd) {
rbbt::bbt_detect_citations(paste(readLines(rmd), collapse = "\n"))
})
names(keys_per_rmd) <- basename(vignettes)

for (rmd in names(keys_per_rmd)) {
message(" ", rmd, ": ", length(keys_per_rmd[[rmd]]), " keys")
}

# Note any keys that appear in only one vignette (informational —
# the union still gets written, no manual reconciliation needed)
all_keys <- sort(unique(unlist(keys_per_rmd)))
for (rmd in names(keys_per_rmd)) {
rmd_only <- setdiff(keys_per_rmd[[rmd]], unlist(keys_per_rmd[setdiff(names(keys_per_rmd), rmd)]))
if (length(rmd_only) > 0) {
message(" Note: ", length(rmd_only), " key(s) appear only in ",
rmd, ": ", paste(rmd_only, collapse = ", "))
}
}

message("\nUnion: ", length(all_keys), " unique keys across ",
length(vignettes), " vignettes")

# --- Fetch bib entries for the full union via BBT ---
bib_text <- rbbt::bbt_bib(all_keys, .action = rbbt::bbt_return)

writeLines(bib_text, out_path)

n_entries <- length(grep("^@", readLines(out_path)))
message("Wrote ", n_entries, " entries to ", out_path)

if (n_entries != length(all_keys)) {
warning("Entry count (", n_entries, ") differs from detected key ",
"count (", length(all_keys), "). Check that BBT is reachable ",
"and all keys exist in Zotero.")
}
13 changes: 13 additions & 0 deletions vignettes/kootenay-lake.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

<!--
After adding or removing pandoc citation markers in this vignette
(or in peace-fwcp.Rmd), regenerate vignettes/references.bib by
running:

Rscript data-raw/regenerate_bib.R

Pulls source records from Zotero via Better BibTeX (rbbt -> BBT).
Requires Zotero running with the BBT plugin enabled. CI does not
run this script — the bib is committed and pkgdown reads it.
-->


```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
Expand Down
13 changes: 13 additions & 0 deletions vignettes/peace-fwcp.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

<!--
After adding or removing pandoc citation markers in this vignette
(or in kootenay-lake.Rmd), regenerate vignettes/references.bib by
running:

Rscript data-raw/regenerate_bib.R

Pulls source records from Zotero via Better BibTeX (rbbt -> BBT).
Requires Zotero running with the BBT plugin enabled. CI does not
run this script — the bib is committed and pkgdown reads it.
-->


```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
Expand Down
1 change: 1 addition & 0 deletions vignettes/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,4 @@ @article{yue_wang2002Applicabilityprewhitening
keywords = {cd-issue-53,snowpack-departure-methodology},
file = {/Users/airvine/Zotero/storage/VSW8UA44/Applicability_of_Prewhitening_to_Eliminate_the_Inf.pdf}
}

Loading