Learn R Programming

assertive (version 0.2-6)

assert_all_are_cas_numbers: 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)

assert_any_are_cas_numbers(x)

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

Arguments

x
Input to check.
.xname
Not intended to be called directly.

Value

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

References

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

Examples

Run this code
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.
dont_stop(assert_all_are_cas_numbers(x))

Run the code above in your browser using DataLab