expect_integers <- function(x) {
m <- gregexpr("[[:digit:]]+", x)
matches <- regmatches(x,m)[[1]]
if (length(matches)==0) {
# this means failure to detect numbers where we expected them
return(list())
} else {
return(as.numeric(matches))
}
}
match_s(expect_integers) ("12 15 16 # some comment") # success
match_s(expect_integers) ("some text") # failure
Run the code above in your browser using DataLab