cas_check | R Documentation |
One-step check for CAS, via format and checksum; optionally preprocess input
cas_check(x, preprocess = TRUE, removeWS = TRUE)
x |
chr. A vector of values to check. Standard CAS notation using hyphens is fine, as all non-digit characters are stripped for checksum calculation |
preprocess |
logi. Trim leading and trailing whitespace and pare all consecutive ( |
removeWS |
logi. Should all whitespace, be removed? Defaults to |
This is mainly a convenience function that combines cas_detect
and cas_checkSum
with
an additional parameter to handle whitespaces. The use case for cas_detect
is broader than this function, and
therefore an argument to explicitly handle whitespaces is not included there, but is here.
Do note that because this implements both format and checksum checks, it is more stringent than either standalone function, which may or may not be desirable. Please see the related functions if you require more granular control.
A logical
vector of length x denoting whether each x is a valid CAS by both
format and the last-digit checksum calculation NA
input values will remain NA
.
The standalone functions are natively vectorized, and since this encompasses the full functionality of
is.cas
, it is arguably a vectorized alternative.
Other cas_functions:
cas_checkSum()
,
cas_detect()
# preprocessing demo x_casOnly <- c("598-42-5", "19438-61-0", "20730-39-6") # all 'real' CAS RNs x_messy <- c("casrn: 598-42-5", "19438-61 - 0", "20730--39-6") cas_check(x_casOnly, preprocess = FALSE) # already known good, preprocess not needed cas_check(x_messy, preprocess = FALSE) # removeWS not enough to handle '--' # NA handling cas_check(c(NA, x_messy, NA)) # NA passed through # NULL handling cas_check(c(NA, NULL, x_messy, NULL, NA)) # NULL removed, length == length(x)-length(is.null(x))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.