Learn R Programming

assertive.data (version 0.0-3)

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

References

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

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab