Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Created May 11, 2015 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TonyLadson/5da98cb2f3d73d621ae2 to your computer and use it in GitHub Desktop.
Save TonyLadson/5da98cb2f3d73d621ae2 to your computer and use it in GitHub Desktop.
Is a value a valid new site number? i.e. 5 capital letters followed by 4 digits
isNewSiteNum <- function(x) {
# returns true if value is missing, or a site number i.e. 5 capitals follows by 4 digits
# otherwise returns false
if(is.na(x)) return(TRUE)
if(!is.character(x)) return(FALSE)
if(str_count(x) != 9) return(FALSE)
str_detect(x, "^[A-Z]{5}[:digit:]{4}") # 5 capitals followed by 4 digits
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment