nearest_arg: nearest_arg

View source: R/nearest_arg.R

nearest_argR Documentation

nearest_arg

Description

It determines the nearest candidate value for each value in arg. As a replacement for base::match.arg since it is more (typo) error tolerant, but if a wrong choice will be done it is difficult to detect.

Usage

nearest_arg(arg, choices, method = "cosine", ...)

Arguments

arg

character: vector or NULL

choices

character: vector of candidate values

method

character: method for distance calculation (default: cosine)

...

further parameters for stringdist::stringdistmatrix

Value

for each value in arg the (first) nearest element of choices

Examples

# match.arg("tow.sided", c("two.sided", "less", "greater")) # will fail
nearest_arg("tow.sided", c("two.sided", "less", "greater")) 
nearest_arg(c("two.sided", "less", "greater"), c("two.sided", "less", "greater"))
nearest_arg(c("two", "two", "ded", "ss", "ea"), c("two.sided", "less", "greater"))

sigbertklinke/exams2moodle documentation built on July 6, 2023, 3:26 p.m.