Skip to contents

[Experimental]

Tries to fuzzy match the genus name from the input dataset to the IUCN genus list (iucnr::iucn_genus). Uses fuzzyjoin::stringdist_left_join() for approximate string matching, allowing for minor differences in the genus names.

Usage

genus_fuzzy_match(df)

Arguments

df

A tibble resulting of apliying function genus_exact_match.

Value

Returns a tibble with aditional columns with information aboout fuzzy matching:

  • matched_genus: Contains the matched genus name (if a match was found) or NA otherwise.

  • fuzzy_match_genus: Logical column indicating whether the genus was successfully matched (TRUE) or not (FALSE).

  • fuzzy_genus_dist: The string distance between the original and matched genus names (only for matched rows).

Details

The function handles cases where the genus name in the input data differs slightly (e.g., due to typos). It assigns the closest match based on string distance (with a maximum distance of 1) and identifies unmatched entries. For genera with multiple fuzzy matches, the function issues a warning, saves the ambiguous matches to a CSV file, and proceeds by selecting the first match. The user is advised to manually curate these ambiguous cases and re-run the function if necessary.

Examples

# Example input tibble

df <- tibble::tibble(
  submitted_name = c("Panthera uncia", "Lynx lynx", "Ara militaris",
                     "Zonotrichia capencis", "Cyathula coriaceas", "Impatienss confussa"),
  or_genus_name = c("Panthera", "Lynx", "Ara", "Zonotrichia", "Cyathula", "Impatienss")
)

# Exact match
node_1_processed <- genus_exact_match(df)

# Fuzzy matching

node_1_FALSE <- node_1_processed |>
dplyr::filter(direct_match_genus == FALSE)

node_2_processed <- genus_fuzzy_match(node_1_FALSE)

print(node_2_processed)
#> # A tibble: 1 × 6
#>   submitted_name matched_genus or_genus_name direct_match_genus fuzzy_genus_dist
#>   <chr>          <chr>         <chr>         <lgl>                         <dbl>
#> 1 Impatienss co… Impatiens     Impatienss    FALSE                             1
#> # ℹ 1 more variable: fuzzy_match_genus <lgl>