Skip to contents

Collapse 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).

Usage

frs_categorize(conn, table, label, cols, values, default = "NONE")

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 TRUE wins.

values

Character vector. Category values corresponding to each column in cols. Must be the same length as cols.

default

Character. Value for rows where no column is TRUE. Default "NONE".

Value

conn invisibly, for pipe chaining.

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)
} # }