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)Diagnostic: IUCN-only species (not NMFS/FWS) with er_score > 1
Evaluate species that:
is_ok = TRUE)extrisk_code does not start with NMFS: or FWS:)extrisk_code starts with IUCN:)er_score > 1librarian::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)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
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 |
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
)
)dbDisconnect(con_sdm, shutdown = TRUE)