
Categorize Features by Priority-Ordered Boolean Columns
Source:R/frs_categorize.R
frs_categorize.RdCollapse multiple boolean classification columns into a single categorical
column. The first TRUE column wins — order of cols defines priority.
Useful for mapping codes (QGIS categorized renderer), reporting categories,
and style registry integration (gq).
Arguments
- conn
A DBI::DBIConnection object (from
frs_db_conn()).- table
Character. Working schema table to update.
- label
Character. Column name for the categorical result.
- cols
Character vector. Boolean columns to check, in priority order. First
TRUEwins.- values
Character vector. Category values corresponding to each column in
cols. Must be the same length ascols.- default
Character. Value for rows where no column is
TRUE. Default"NONE".
Details
Pipeable after frs_classify():
conn |>
frs_classify("working.streams", label = "co_spawning", ...) |>
frs_classify("working.streams", label = "co_rearing", ...) |>
frs_categorize("working.streams", label = "habitat_type",
cols = c("co_spawning", "co_rearing", "accessible"),
values = c("CO_SPAWNING", "CO_REARING", "ACCESSIBLE"),
default = "INACCESSIBLE")Examples
if (FALSE) { # \dontrun{
conn <- frs_db_conn()
# After classifying habitat, collapse to a single mapping code
conn |>
frs_categorize("working.streams",
label = "habitat_type",
cols = c("co_spawning", "co_rearing", "co_lake_rearing", "accessible"),
values = c("CO_SPAWNING", "CO_REARING", "CO_LAKE_REARING", "ACCESSIBLE"),
default = "INACCESSIBLE")
DBI::dbDisconnect(conn)
} # }