Skip to contents

Downloads and compiles the simple (non-composite) coded-field reference tables from the IMR NMD Reference API into a single long-format lookup. These are the Biotic columns flagged as codes of type KeyType (e.g. sex, maturationstage, samplequality, gearcondition) whose meaning is otherwise only resolvable against the API. The result is written to the DuckDB database as the codeindex table by compileDatabase, so agents and the Shiny app can decode these fields offline with a join instead of a per-code network call.

Usage

prepareReferenceCodes(tables = NULL, lang = c("en", "no"))

Arguments

tables

Character vector of reference datasets to pull. Defaults to the coded KeyType columns that occur in mission/stnall/indall and are exposed as Reference API datasets. The vector may be named: names are the Biotic column (written to the reftable column so a join on the column name works), values are the Reference API dataset that defines the codes. Unnamed elements use the dataset name as the label. Note that a few Biotic columns map to a differently named reference dataset. The stationtype column resolves against the fishstationtype dataset and is handled here through that naming. The gear column resolves against the equipment table — handled separately by prepareGearList and therefore not included here.

lang

Language for shortname/description: "en" (default) or "no".

Value

A data.table with columns reftable, code, shortname, and description, stacked across all successfully read tables.

Details

Reads each table from .../reference/v2/dataset/{table} (the same endpoint family used by prepareGearList) and keeps only the code -> meaning mapping. Deprecated reference rows are excluded. Editor-identity columns from the registry (updatedBy, insertedBy, timestamps, ...By fields) are dropped on purpose so no staff usernames land in the database. Tables that fail to download (e.g. off the IMR network) are skipped with a warning rather than aborting the build. Composite reference tables that are keyed by taxa and/or sex (specialstage, eggstage, moultingstage, spawningfrequency) are intentionally not handled here — they need a taxa/sex-aware lookup and are left to the API.

Author

Mikko Vihtakari (Institute of Marine Research)