R/sanitize_identifiers.R

Defines functions sanitize_identifiers

sanitize_identifiers <- function(x,
                                 regex = "[^a-zA-Z0-9_]",
                                 warningMsg = "Found (and removed) illegal characters in code identifiers %s. They were changed to %s.") {

  x <- trimws(x);

  sanitizedIds <-
    gsub(regex, "", x);

  illegalIds <- x != sanitizedIds;
  if (any(illegalIds)) {
    warning(
      sprintf(
        message,
        vecTxtQ(x[illegalIds]),
        vecTxtQ(sanitizedIds[illegalIds])
      )
    );
  }

  return(sanitizedIds);

}
gitlab-r-packages-mirror/rock documentation built on Dec. 3, 2024, 5:40 p.m.