Skip to content

Partial matching of species in errors for psdVal() and wsVal() #132

@droglenc

Description

@droglenc

Currently if the user mis-capitalizes, but otherwise spells correctly, the name in species= for psdVal() and wsVal() (and related functions) then an error is thrown with a gentle reminder to check the capitalization. However, if species is simply mis-spelled then a less informative terse error about the species not being available is sent. Consider using the "fuzzy matching" found in the stringdist package to send a more useful error message.

library(stringdist)
library(FSA)
specs <- unique(PSDlit$species)

# correct spelling
tmp <- ain(specs,"Brown Trout")
specs[tmp]

# simple misspellings
tmp <- ain(specs,"Brow Trout",maxDist=2)
specs[tmp]

tmp <- ain(specs,"Crown Trout",maxDist=2)
specs[tmp]

tmp <- ain(specs,"Brow Trut",maxDist=2)
specs[tmp]

# worse misspellings
tmp <- ain(specs,"Bro Trout",maxDist=2)
specs[tmp]

tmp <- ain(specs,"Bro Trut",maxDist=2)
specs[tmp]

# worse misspellings ... try different maxDist
tmp <- ain(specs,"Bro Trout",maxDist=3)
specs[tmp]

tmp <- ain(specs,"Bro Trut",maxDist=3)
specs[tmp]

Either need to decide on a maxDist= to use and if it returns nothing then send the terse message or perhaps iteratively increase maxDist= to some pre-determine level (say 3) and return a message with the first non-empty result or, if all are empty, the terse message.

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions