R/substitute_non_alphanumeric_and_punctuation.R

Defines functions substitute_non_alphanumeric_and_punctuation

Documented in substitute_non_alphanumeric_and_punctuation

#' Remove non-alphanumeric and punctuation characters from strings '
#'
#' A wrapper for gsub that substitutes non-alphanumeric and punctuation
#' characters by "_". Initially idealized for generating filenames without
#' reserved characters.
#'
#' @param x the string to process.
#' @param pattern see ?gsub.
#' @param replacement see ?gsub.
#' @keywords replace, substitute
#' @export
#' @examples
#' substitute_non_alphanumeric_and_punctuation("1 !#$%* 11 ;'. R Tutorial")

substitute_non_alphanumeric_and_punctuation <-
  function(x, pattern = "[^A-Za-z0-9,;._-]", replacement = "_") {
    gsub(pattern,
         replacement,
         x)
  }
mtcruz/mtcruzr documentation built on Dec. 26, 2019, 11:04 p.m.