R/sanitize_for_DiagrammeR.R

Defines functions sanitize_for_DiagrammeR

Documented in sanitize_for_DiagrammeR

#' Sanitize for DiagrammeR
#'
#' Basically a wrapper for [gsub()] to sanitize a string for
#' DiagrammeR
#'
#' @param x The string or vector
#' @param regExReplacements A list of two-element character vectors; first element
#' should be the element to search, and the second element, the replacement.
#'
#' @return The sanitized character vector
#' @export
#'
#' @examples justifier::sanitize_for_DiagrammeR("This is or isn't problematic");
sanitize_for_DiagrammeR <-
  function(x,
           regExReplacements = justifier::opts$get("regExReplacements")) {

  for (i in seq_along(regExReplacements)) {
    x <- gsub(regExReplacements[[i]][1],
              regExReplacements[[i]][2],
              x);
  }
  return(x);
}

Try the justifier package in your browser

Any scripts or data that you put into this service are public.

justifier documentation built on March 7, 2023, 6:59 p.m.