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
6 changes: 1 addition & 5 deletions R/lnk_pipeline_break.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ lnk_pipeline_break <- function(conn, aoi, cfg, loaded, schema,
row <- wsg_sp[wsg_sp$watershed_group_code == aoi, ]
if (nrow(row) == 0) return(character(0))

spp_cols <- c("bt", "ch", "cm", "co", "ct", "dv",
"pk", "rb", "sk", "st", "wct")
present <- vapply(spp_cols,
function(x) identical(row[[x]], "t"), logical(1))
sp <- toupper(spp_cols[present])
sp <- .lnk_wsg_species_present(row)

# bcfishfobs records cutthroat as CT, CCT, ACT, or CT/RB — all
# resolve to the same species in wsg_species_presence.
Expand Down
8 changes: 1 addition & 7 deletions R/lnk_pipeline_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,5 @@ lnk_pipeline_species <- function(cfg, loaded, aoi) {
row <- wsg_sp[wsg_sp$watershed_group_code == aoi, ]
if (nrow(row) == 0) return(character(0))

spp_cols <- c("bt", "ch", "cm", "co", "ct", "dv",
"pk", "rb", "sk", "st", "wct")
present <- vapply(spp_cols,
function(x) identical(row[[x]], "t"), logical(1))
aoi_species <- toupper(spp_cols[present])

intersect(configured, aoi_species)
intersect(configured, .lnk_wsg_species_present(row))
}
18 changes: 18 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,21 @@
on.exit(DBI::dbClearResult(res))
DBI::dbColumnInfo(res)$name
}


#' Species codes flagged present in a wsg_species_presence row.
#'
#' Treats every column except `watershed_group_code` and `notes` as a
#' species presence flag. Returns uppercased codes for cells equal to
#' the literal string `"t"`.
#'
#' Driven by the CSV header rather than a hardcoded vector so adding a
#' new species column (e.g. `ko`) propagates to every callsite without
#' a code edit. See link#106.
#' @noRd
.lnk_wsg_species_present <- function(row) {
spp_cols <- setdiff(names(row), c("watershed_group_code", "notes"))
present <- vapply(spp_cols,
function(x) identical(row[[x]], "t"), logical(1))
toupper(spp_cols[present])
}
Loading