Bundle-aware WSG resolver. Given a config + loaded overrides and an
optional focal set, returns the character vector of WSG codes that
should be modelled — composing FWA drainage closure (via
fresh::frs_wsg_drainage()) with the bundle's species-presence
filter (link#157).
Arguments
- cfg
An
lnk_configobject fromlnk_config().- loaded
Named list of tibbles from
lnk_load_overrides(). Must carrywsg_species_presence.- wsgs
Character vector of focal WSG codes, or
NULL(default) for province mode. Codes are upper-cased internally before use.- expand
Logical. When
wsgsis non-NULL,TRUE(default) closure-expands viafresh::frs_wsg_drainage();FALSEuses the input as-is (species-filter only).- conn
Optional DBI::DBIConnection. Only used in closure mode (
wsgsnon-NULLandexpand = TRUE). WhenNULL(default), one is opened vialnk_db_conn()(env-var-driven) and closed on exit. Pass an explicit conn to control the target DB (e.g. local docker fwapg vs an env-pinned tunnel) — recommended in scripts.
Value
Character vector of WSG codes. Province mode returns the
species-filtered set sorted alphabetically; closure mode preserves the
downstream-first order from fresh::frs_wsg_drainage(); strict mode
preserves the caller-provided focal order. WSGs dropped by the
species filter (closure / strict modes) are reported via message().
Details
Three call patterns dispatched by wsgs + expand:
wsgs = NULL— province mode: every WSG inloaded$wsg_species_presencethat has at least one ofcfg$speciesflagged present.wsgs = c(...)+expand = TRUE(default) — closure mode: expand the focal set to its drainage closure (focal + every WSG they flow through, ordered downstream-first), then species-filter. Requires a DB connection — passconnexplicitly, or one is opened fromlnk_db_conn()(defaults to env-var-driven) and closed on exit.wsgs = c(...)+expand = FALSE— strict mode: species-filter the input verbatim, no closure expansion, no DB.
Species filter: a WSG is kept if any of tolower(cfg$species)
columns in loaded$wsg_species_presence carries "t" (or "TRUE" /
TRUE, defensively). DS-first ordering from the closure is preserved.
Examples
if (FALSE) { # \dontrun{
cfg <- lnk_config("bcfishpass")
loaded <- lnk_load_overrides(cfg)
# Province mode — all bundle-species WSGs
lnk_wsg_resolve(cfg, loaded)
# Study-area mode — focal + drainage closure (default)
lnk_wsg_resolve(cfg, loaded, wsgs = c("PARS", "BULK"))
#> [1] "KISP" "KLUM" "LKEL" "LSKE" "MSKE" "USKE" "BULK" "FINA"
#> "LBTN" "LPCE" "MORR" "PARA" "PCEA" "UPCE" "PARS"
# Strict mode — exactly these, species-filtered, no closure
lnk_wsg_resolve(cfg, loaded, wsgs = c("BBAR", "BULK"), expand = FALSE)
} # }
