is.cas: Check if input is a valid CAS

Description Usage Arguments Value Note References Examples

View source: R/utils.R

Description

This function checks if a string is a valid CAS registry number. A valid CAS is 1) separated by two hyphes into three parts; 2) the first part consists from two up to seven digits; 3) the second of two digits; 4) the third of one digit (check digit); 5) the check digits corresponds the checksum. The checksum is found by taking the last digit (excluding the check digit) multiplyingit with 1, the second last multiplied with 2, the third-last multiplied with 3 etc. The modulo 10 of the sum of these is the checksum.

Usage

1
is.cas(x, verbose = getOption("verbose"))

Arguments

x

character; input CAS

verbose

logical; print messages during processing to console?

Value

a logical

Note

This function can only handle one CAS string

References

Eduard Szöcs, Tamás Stirling, Eric R. Scott, Andreas Scharmüller, Ralf B. Schäfer (2020). webchem: An R Package to Retrieve Chemical Information from the Web. Journal of Statistical Software, 93(13). doi: 10.18637/jss.v093.i13.

Examples

1
2
3
4
5
6
is.cas('64-17-5')
is.cas('64175')
is.cas('4-17-5')
is.cas('64-177-6')
is.cas('64-17-55')
is.cas('64-17-6')

Example output

[1] TRUE
Less than 2 hyphens in string.
[1] FALSE
First part with more than 7 digits!
[1] FALSE
Second part has not two digits!
[1] FALSE
Third part has not 1 digit!
[1] FALSE
Checksum is not correct! 5 vs. 6
[1] FALSE

webchem documentation built on Dec. 11, 2021, 9:54 a.m.