Match taxa in the provided field fld of the data frame df to the unique
WoRMS identifier (aphia_id) and return df with prepended aphia_id
column. Update database tables taxa_wm with full WoRMS taxonomic records
and metadata on uniquely matching taxa in database table taxa also using
fields tbl_str and fld_str.
wm_add_aphia_id(
df,
fld,
tbl_str = deparse(substitute(df)),
fld_str = deparse(substitute(fld))
)data frame
unquoted field name containing taxonomic field, eg taxa
the source table to be written into the database referenced in taxa.tbl
the source field to be written into the database referenced in taxa.fld
the original data frame df with aphia_id column prepended
Perform the match with the following order of precedence:
Existing match for in the database taxa table
Exact match in WoRMS REST API with wm_rest() having operation="AphiaRecordsByMatchNames"
Fuzzy match in WoRMS REST API with wm_rest() having operation="AphiaRecordsByNames"
With all possible matches made, proceed to:
Prepend the input data frame df with the matched column aphia_id.
Populate taxa table in database with rows containing:
tbl: tbl_str
fld: fld_str
taxa: unique values of fld
aphia_id: matching WoRMS identifier, possibly NA if no match found
Fetch full WoRMS records for any new taxa.aphia_ids using
wm_rest() with operation="AphiaRecordsByAphiaIDs", and append to taxa_wm table.
if (FALSE) {
tmp_test <- tibble::tribble(
~common, ~scientific,
"Minke whale", "Balaenoptera acutorostrata",
"Blue whale", "Balaenoptera musculus")
wm_add_aphia_id(df_test, scientific, tbl_str = "tmp_test")
}