Learn R Programming

assertive.data (version 0.0-3)

assert_all_are_isbn_codes: Does the character vector contain ISBN book codes?

Description

Checks that the input contains ISBN-10 or ISBN-13 book codes.

Usage

assert_all_are_isbn_codes(x, type = c("10", "13"), na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_isbn_codes(x, type = c("10", "13"), na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

is_isbn10_code(x, .xname = get_name_in_parent(x))

is_isbn13_code(x, .xname = get_name_in_parent(x))

is_isbn_code(x, type = c("10", "13"))

Arguments

x

Input to check.

type

Either "isbn10", "isbn13" or both (for matching either type).

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be called directly.

Value

A logical vector that is TRUE when the input contains valid ISBN book codes.

Examples

Run this code
# NOT RUN {
x10 <- c(
  hyphens             = "0-387-98503-4",
  spaces              = "0 387 98503 4",
  just_numbers        = "0387985034",
  too_long            = "00-387-98503-4",
  too_short           = "0-387-9850-4",
  non_numeric         = "Z-387-98503-4",
  invalid_check_digit = "0-387-98503-5",
  missing             = NA
)
x13 <- c(
  hyphens             = "978-0-387-98503-9",
  spaces              = "978 0 387 98503 9",
  just_numbers        = "9780387985039",
  too_long            = "9978-0-387-98503-9",
  too_short           = "978-0-387-9850-9",
  non_numeric         = "Z78-0-387-9850-9",
  invalid_check_digit = "978-0-387-98503-8",
  missing             = NA
)
is_isbn_code(x10, type = "10")
assert_any_are_isbn_codes(x10, type = "10")
is_isbn_code(x13, type = "13")
assert_any_are_isbn_codes(x13, type = "13")
# These checks should fail.
assertive.base::dont_stop(assert_all_are_isbn_codes(x10, type = "10"))
assertive.base::dont_stop(assert_all_are_isbn_codes(x13, type = "13"))
# }

Run the code above in your browser using DataLab