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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: link
Title: Stream Network Habitat Interpretation (Experimental)
Version: 0.41.2
Version: 0.41.3
Date: 2026-05-27
Authors@R: c(
person("Allan", "Irvine", , "airvine@newgraphenvironment.com",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# link 0.41.3

`lnk_wsg_resolve()` gains an optional `conn` argument so callers can control the DB connection rather than relying on env-var-driven `lnk_db_conn()`. When `conn = NULL` (default), behaviour is unchanged — `lnk_db_conn()` is used as before. The change matters in environments where `PG_*_SHARE` env vars (or `~/.Renviron`) point at a tunnel that isn't reachable: `data-raw/study_area_wsgs.R` now opens a local docker fwapg connection explicitly and passes it through, matching every other driver script's `localhost:5432/fwapg postgres/postgres` pattern (and the pre-#207 inline behaviour). Strict mode and province mode remain DB-free; `conn` is consulted only in closure mode (`wsgs` non-`NULL` + `expand = TRUE`). Latent on the v0.41.0 release; exposed by the v0.41.1 study-area run when the dispatcher's `~/.Renviron` was pinned to the dead db_newgraph tunnel.

# link 0.41.2

`data-raw/study_area_run.sh` pre-flight bug fix exposed by v0.41.1's `--schema=` flag. The pre-flight check for the bcfp reference view was looking in `$SCHEMA.streams_vw_bcfp` (the override-able persist schema), but the bcfp reference is hard-coded to `fresh.streams_vw_bcfp` in `R/lnk_compare_mapping_code.R:78` — it's a constant comparison reference, not a per-run output. The coincidence held while `$SCHEMA` was always `"fresh"`; the new flag exposed the latent bug. Now the pre-flight always checks `fresh.streams_vw_bcfp`, independent of `$SCHEMA`.
Expand Down
18 changes: 14 additions & 4 deletions R/lnk_wsg_resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#' - `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.
#' Opens a connection via [lnk_db_conn()] and closes it on exit.
#' Requires a DB connection — pass `conn` explicitly, or one is
#' opened from [lnk_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.
#'
Expand All @@ -30,6 +32,11 @@
#' @param expand Logical. When `wsgs` is non-`NULL`, `TRUE` (default)
#' closure-expands via [fresh::frs_wsg_drainage()]; `FALSE` uses the
#' input as-is (species-filter only).
#' @param conn Optional [DBI::DBIConnection-class]. Only used in closure
#' mode (`wsgs` non-`NULL` and `expand = TRUE`). When `NULL` (default),
#' one is opened via [lnk_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.
#'
#' @return Character vector of WSG codes. Province mode returns the
#' species-filtered set sorted alphabetically; closure mode preserves the
Expand Down Expand Up @@ -57,7 +64,8 @@
#' # Strict mode — exactly these, species-filtered, no closure
#' lnk_wsg_resolve(cfg, loaded, wsgs = c("BBAR", "BULK"), expand = FALSE)
#' }
lnk_wsg_resolve <- function(cfg, loaded, wsgs = NULL, expand = TRUE) {
lnk_wsg_resolve <- function(cfg, loaded, wsgs = NULL, expand = TRUE,
conn = NULL) {
if (!inherits(cfg, "lnk_config")) {
stop("cfg must be an lnk_config object (from lnk_config())",
call. = FALSE)
Expand Down Expand Up @@ -111,8 +119,10 @@ lnk_wsg_resolve <- function(cfg, loaded, wsgs = NULL, expand = TRUE) {
}

# Closure mode ---------------------------------------------------------
conn <- lnk_db_conn()
on.exit(try(DBI::dbDisconnect(conn), silent = TRUE), add = TRUE)
if (is.null(conn)) {
conn <- lnk_db_conn()
on.exit(try(DBI::dbDisconnect(conn), silent = TRUE), add = TRUE)
}
closure <- fresh::frs_wsg_drainage(conn, focal)
# Preserve DS-first order from frs_wsg_drainage by indexing closure,
# not the modelable set
Expand Down
12 changes: 11 additions & 1 deletion data-raw/study_area_wsgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ if (identical(Sys.getenv("LNK_LOAD"), "loadall")) {
suppressPackageStartupMessages(library(link))
}

suppressPackageStartupMessages({
library(DBI); library(RPostgres)
})
# Force local docker fwapg regardless of PG_*_SHARE env (matches every
# other driver script and the pre-#207 inline behaviour) — env-var
# defaults point at the db_newgraph tunnel which is dead on M1.
conn <- DBI::dbConnect(RPostgres::Postgres(), host = "localhost", port = 5432,
dbname = "fwapg", user = "postgres", password = "postgres")
on.exit(try(DBI::dbDisconnect(conn), silent = TRUE), add = TRUE)

cfg <- lnk_config(config)
loaded <- lnk_load_overrides(cfg)
keep <- lnk_wsg_resolve(cfg, loaded, wsgs = focal)
keep <- lnk_wsg_resolve(cfg, loaded, wsgs = focal, conn = conn)

if (length(keep) == 0L) {
stop("no modelable WSGs after species-presence filter", call. = FALSE)
Expand Down
12 changes: 10 additions & 2 deletions man/lnk_wsg_resolve.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.