assert_all_are_cas_numbers {assertive.data}R Documentation

Does the character vector contain CAS registry numbers?

Description

Checks that the input contains Chemical Abstract Service registry numbers.

Usage

assert_all_are_cas_numbers(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_cas_numbers(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_cas_number(x)

Arguments

x

Input to check.

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".

Value

A logical vector that is TRUE when the input contains valid CAS registry numbers.

Note

CAS numbers take the form of 1 to 7 digits followed by a hyphen, followed by 2 digits, another hyphen and a final check digit.

References

Chemspider (https://www.chemspider.com) is a good service for looking up CAS numbers.

Examples

x <- c(
  water            = "7732-18-5", 
  d_glucose        = "50-99-7",
  l_glucose        = "921-60-8",
  no_hyphens       = "7732185", 
  two_check_digits = "7732-18-55",
  bad_check_digit  = "7732-18-4",
  missing          = NA
)
is_cas_number(x)
assert_any_are_cas_numbers(x)
#These examples should fail.
assertive.base::dont_stop(assert_all_are_cas_numbers(x))

[Package assertive.data version 0.0-3 Index]