Skip to contents

This function processes an input string that contains an ISBN (or a compound string where the first element is the ISBN). It first removes unwanted characters (keeping only digits, commas, and spaces), then uses the GoFish function to further process the string. The function splits the cleaned string by spaces or commas to extract a candidate ISBN. If the candidate ISBN is in ISBN10 format, it is converted to ISBN13 by prepending "978", recalculating the check digit, and concatenating the result. Finally, the function validates that the resulting ISBN is a valid ISBN13, i.e., it is 13 digits long and starts with either "978" or "979".

Usage

CheckIsbn(key)

Arguments

key

A character string that contains an ISBN or a compound string where the first element is the ISBN.

Value

A cleaned and validated ISBN string. If the resulting ISBN does not meet the expected criteria, the function returns NULL.

Details

The function performs the following steps:

  1. Cleans the input key by removing all characters except digits, commas, and spaces.

  2. Processes the cleaned key using the GoFish function (which must be defined in your environment).

  3. Splits the resulting string by spaces and commas to extract the first candidate ISBN.

  4. If the candidate is in ISBN10 format (10 characters), it converts it to ISBN13 by:

    1. Converting the first 9 digits to numeric.

    2. Prepending the ISBN13 prefix "978".

    3. Calculating the ISBN13 check digit using alternating weights of 1 and 3.

    4. Concatenating the digits to form the full ISBN13.

  5. Validates that the final key is a valid ISBN13 (i.e., 13 digits long and starting with "978" or "979").

Examples

if (FALSE) { # \dontrun{
# Example with a compound string where the first part is the ISBN:
isbn_input <- "316148410X, some extra text"
valid_isbn <- CheckIsbn(isbn_input)

# Example converting an ISBN10 to ISBN13:
isbn10 <- "316148410X"
valid_isbn <- CheckIsbn(isbn10)
} # }