Title: | Calculate and Verify Check Digits |
---|---|
Description: | Check digits are used like file hashes to verify that a number has been transcribed accurately. The functions provided by this package help to calculate and verify check digits according to various algorithms. |
Authors: | Justin Brantley [aut, cre] |
Maintainer: | Justin Brantley <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2025-03-10 03:02:40 UTC |
Source: | https://gitlab.com/fascinatingfingers/checkdigit |
Append a check digit to a value
AppendCheckDigit(x, method)
AppendCheckDigit(x, method)
x |
character vector of values requiring a check digit |
method |
a character value naming the check digit algorithm to use |
character vector similar to x
but with a check digit appended to
each value
AppendCheckDigit("1234", "Verhoeff") # 12340
AppendCheckDigit("1234", "Verhoeff") # 12340
The Verhoeff algorithm is appropriate for numerical data and detects all single-digit substitutions (x to y) and adjacent digit transpositions (xy to yx). In addition, the Verhoeff check digit can detect most twin errors (xx to yy), jump twin errors (xyx to zyz), jump transpositions (xyz to zyx), and phonetic errors ("sixty" to "sixteen").
AppendCheckDigit.Verhoeff(x) VerifyCheckDigit.Verhoeff(x)
AppendCheckDigit.Verhoeff(x) VerifyCheckDigit.Verhoeff(x)
x |
character vector of values |
Verhoeff, J. "Error Detecting Decimal Codes", Mathematical Centre Tract 29, The Mathematical Centre, Amsterdam, 1969.
Verify whether a value ends with a valid check digit
VerifyCheckDigit(x, method)
VerifyCheckDigit(x, method)
x |
character vector of values to verify |
method |
a character value naming the check digit algorithm to use |
logical vector the same length as x
VerifyCheckDigit("12340", "Verhoeff") # TRUE VerifyCheckDigit("21340", "Verhoeff") # FALSE VerifyCheckDigit("13240", "Verhoeff") # FALSE VerifyCheckDigit("12430", "Verhoeff") # FALSE VerifyCheckDigit("12304", "Verhoeff") # FALSE
VerifyCheckDigit("12340", "Verhoeff") # TRUE VerifyCheckDigit("21340", "Verhoeff") # FALSE VerifyCheckDigit("13240", "Verhoeff") # FALSE VerifyCheckDigit("12430", "Verhoeff") # FALSE VerifyCheckDigit("12304", "Verhoeff") # FALSE