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
KeyTypecolumns that occur inmission/stnall/indalland are exposed as Reference API datasets. The vector may be named: names are the Biotic column (written to thereftablecolumn 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. Thestationtypecolumn resolves against thefishstationtypedataset and is handled here through that naming. Thegearcolumn resolves against theequipmenttable — handled separately byprepareGearListand 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.