DYM (version 0.2)

findSimilarName: Looks for approximate matches to x (the first argument) within name (the second) argument.

Description

Looks for approximate matches to x (the first argument) within name (the second) argument.

Usage

findSimilarName(x, names, threshold = 2, max_n = 10, ignoreCase = FALSE)

Arguments

x
A string giving the (misspelt) name to search for.
names
A character vector of correct names to match against.
threshold
The maximum distance between the misspell (x) and the correct answer (in name).
max_n
An integer limiting the number of results. Passed to head.
ignoreCase
A logical value indicating whether differences in case should be ignored when matching. Passed to adist.

See Also

adist calculates the distance between strings. agrep and stringdist-package provide alternate metrics for these distances.

Examples

Run this code

x <- "logg"
names <- DYM:::getNames(x)
# Increasing threshold increases the number of hits, upto max_n = 10
lapply(
  stats::setNames(0:4, 0:4), 
  function(i) DYM:::findSimilarName(x, names, threshold = i)
)

# Use max_n = Inf to return all hits
DYM:::findSimilarName(x, names, threshold = 3, max_n = Inf)

# Negative max_n returns all hits except the last max_n
DYM:::findSimilarName(x, names, threshold = 3, max_n = -40)

# Set ignoreCase = TRUE to get more matches that differ by letter case
DYM:::findSimilarName(x, names, ignoreCase = TRUE)

Run the code above in your browser using DataCamp Workspace