Diagnostic: IUCN-only species (not NMFS/FWS) with er_score > 1

Published

2026-02-18 17:51:00

1 Overview

Evaluate species that:

  • pass quality checks (is_ok = TRUE)
  • are not listed by NMFS or FWS (extrisk_code does not start with NMFS: or FWS:)
  • have an IUCN code (extrisk_code starts with IUCN:)
  • have er_score > 1
Code
librarian::shelf(
  DBI,
  dplyr,
  DT,
  duckdb,
  glue,
  here,
  knitr,
  stringr,
  tidyr,
  quiet = T
)

source(here("libs/paths.R"))

con_sdm <- dbConnect(duckdb(), sdm_db, read_only = TRUE)

2 Query taxa

Code
d <- tbl(con_sdm, "taxon") |>
  filter(
    is_ok == TRUE,
    er_score > 1
  ) |>
  collect() |>
  filter(
    str_starts(extrisk_code, "IUCN:")
  )

# extract iucn code from extrisk_code
d <- d |>
  mutate(
    iucn_code = str_remove(extrisk_code, "^IUCN:")
  )

message(glue("{nrow(d)} IUCN-only taxa with er_score > 1"))
194 IUCN-only taxa with er_score > 1

3 IUCN codes by species category

Code
d |>
  count(sp_cat, iucn_code) |>
  pivot_wider(
    names_from = iucn_code,
    values_from = n,
    values_fill = 0
  ) |>
  arrange(sp_cat) |>
  kable()
sp_cat EN NT VU CR
bird 8 11 7 0
coral 6 13 3 10
fish 17 34 46 7
invertebrate 6 14 8 3
mammal 0 1 0 0

4 Full listing

Code
d |>
  mutate(
    mapsp = glue(
      "<a href='https://shiny.marinesensitivity.org/mapsp/?mdl_seq={mdl_seq}'
         target='_blank'>{mdl_seq}</a>"
    ),
    worms = ifelse(
      !is.na(worms_id),
      glue(
        "<a href='https://www.marinespecies.org/aphia.php?p=taxdetails&id={worms_id}'
           target='_blank'>{worms_id}</a>"
      ),
      NA_character_
    )
  ) |>
  select(
    sp_cat,
    scientific_name,
    common_name,
    mapsp,
    worms,
    iucn_code,
    er_score,
    is_mmpa,
    is_mbta,
    is_bcc
  ) |>
  arrange(sp_cat, desc(er_score), scientific_name) |>
  datatable(
    escape = FALSE,
    filter = "top",
    options = list(
      pageLength = 25,
      autoWidth = TRUE
    )
  )
Code
dbDisconnect(con_sdm, shutdown = TRUE)