Package 'verhoeff'

Title: Implementation of the 'Verhoeff' Check Digit Algorithm
Description: An implementation of the 'Verhoeff' algorithm for calculating check digits (Verhoeff, J. (1969) <doi:10.1002/zamm.19710510323>). Functions are provided to calculate a check digit given an input number, calculate and append a check digit to an input number, and validate that a check digit is correct given an input number.
Authors: Conor Neilson
Maintainer: Conor Neilson <[email protected]>
License: GPL-3
Version: 0.4.0.9000
Built: 2024-11-19 05:10:59 UTC
Source: https://github.com/condwanaland/verhoeff

Help Index


calculate_digit

Description

Calculates a single Verhoeff Check Digit. This function is exported, but it would usually be called from one of the 'verhoeff_*' wrapper functions

Usage

calculate_digit(number, d5, d5_p, inv_v)

Arguments

number

A number you want to calculate the check digit for

d5

The verhoeff d5 matrix. Retrievable with create_verhoeff_matrices()$d5

d5_p

The verhoeff p matrix. Retrievable with create_verhoeff_matrices()$d5_p

inv_v

The verhoeff inv matrix. Retrievable with create_verhoeff_matrices()$inv_v

Value

A single integer

Examples

dat <- verhoeff::create_verhoeff_matrices()
calculate_digit(5, dat$d5, dat$d5_p, dat$inv_v)

prepare_number

Description

Takes a number and prepares it for input to the verhoeff algorithim by reversing it

Usage

prepare_number(number)

Arguments

number

A single number that can be coerced to numeric

Value

A numeric vector of length equal to number of digits in the input

Examples

prepare_number(1234)

verhoeff_append

Description

Return a number with its check digit appended

Usage

verhoeff_append(number, sep = "-")

Arguments

number

The number to calculate a check digit for

sep

A separator for the two numbers

Value

Numeric vector of length equal to its input

Examples

verhoeff::verhoeff_append(123)

verhoeff_calculate

Description

verhoeff_calculate

Usage

verhoeff_calculate(number, as_list = FALSE)

Arguments

number

The vector of numbers you want a check digit for

as_list

Return the results as a list? Defaults to false

Value

Vector or list of check digits

Examples

verhoeff_calculate(1234)

verhoeff_validate

Description

Enter a number, and an existing check digit. Function will return true if the supplied check digit is a correct verhoeff check digit for the given number

Usage

verhoeff_validate(number, check_digit)

Arguments

number

A numerical input

check_digit

An existing check digit for the input number

Value

Logical vector

Examples

verhoeff::verhoeff_validate(123, 3)