Skip to content

Commit

Permalink
Option if fuzzy_match accepted list is empty for a given letter (#218)
Browse files Browse the repository at this point in the history
Needed to add `if else` loop to `fuzzy_match.R` to only search for fuzzy matches if the subset accepted list (with same first letter) is non-empty. If there were no strings on the accepted list with the same first letter as the input text, warnings were generated.

Test added to check this functionality.
  • Loading branch information
ehwenk authored May 1, 2024
1 parent a8c7632 commit d6f4a6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/fuzzy_match.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fuzzy_match <- function(txt, accepted_list, max_distance_abs, max_distance_rel,
unique()

## identify the number of characters that must change for the text string to match each of the possible accepted names
if (length(accepted_list) > 0) {
distance_c <- stringdist::stringdist(txt, accepted_list, method = "dl")

## identify the minimum number of characters that must change for the text string to match a string in the list of accepted names
Expand All @@ -83,6 +84,10 @@ fuzzy_match <- function(txt, accepted_list, max_distance_abs, max_distance_rel,
return(NA)
}

} else {
return(NA)
}

# function to check if a match is ok
check_match <- function(potential_match) {

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-operation_outputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,17 @@ test_that("identifier column works when mismatch between unique taxa and unique
}

)

test_that("No warnings if trying to match input name to empty accepted name set.", {

expect_equal(
fuzzy_match(
txt = "Kallstroemie",
accepted_list = resources$family_synonym$canonical_name,
max_distance_abs = 2,
max_distance_rel = 0.3,
n_allowed = 1,
epithet_letters = 1
), NA)
}
)

0 comments on commit d6f4a6e

Please sign in to comment.