
Add Link Between Specimen and Individual
dot-add_link_specimens.RdCreates links between herbarium specimens and individual trees in the database. Includes validation to ensure foreign key references exist.
Usage
.add_link_specimens(
new_data,
col_names_select = NULL,
col_names_corresp = c("id_specimen", "id_n", "id_linktype"),
launch_adding_data = FALSE,
validate = TRUE,
con = NULL
)Arguments
- new_data
Tibble with column id_specimen, either id_linktype or type, and - depending on the scope of that link type - id_n (individual-level) or id_liste_plots (plot-level).
- col_names_select
Character vector of column names in new_data to use. If NULL, uses all columns of new_data.
- col_names_corresp
Character vector of target column names. Default: c("id_specimen", "id_n", "id_linktype")
- launch_adding_data
Logical. If TRUE, links are actually added to database. Default FALSE for safety.
- validate
Logical. If TRUE, validates FK references before adding. Default TRUE.
- con
Database connection. If NULL, calls call.mydb()
Details
Link types, and the column each one fills: - type_individual: specimen collected from this specific individual (id_n) - referenced_individual: specimen of the same species from a different individual (id_n) - reference_plot: specimen collected within a plot, the individual tree unknown (id_liste_plots)
Which of the two a type expects is `linktypelist.scope`, checked here.
The function: 1. Renames columns to standard names 2. Checks for duplicate links (same specimen, individual, type and plot) 3. Validates FK references and link scope if validate=TRUE 4. Sets audit columns (created_by, created_at) 5. Adds links if launch_adding_data=TRUE
Author
Gilles Dauby, gilles.dauby@ird.fr