R/misc.R

Defines functions clean_messages remove_nbsp remove_newlines removeURLS removeHTMLtags

#' @noRd
removeHTMLtags <- function(htmlString) {
  clean_string <- gsub(pattern = "<.*?>", replacement = "", x = htmlString)
  clean_string <- gsub(pattern = "<a", replacement = "", x = clean_string)
  clean_string <- gsub(pattern = "href", replacement = "", x = clean_string)
  clean_string
}

#' @noRd
removeURLS <- function(htmlString) {
  gsub(pattern = "https?://[^ ]+", replacement = "", x = htmlString)
}

#' @noRd
remove_newlines <- function(htmlString) {
  gsub(pattern = "[\r\n]", replacement = "", x = htmlString)
}

#' @noRd
remove_nbsp <- function(htmlString) {
  clean_string <- gsub(pattern = "&nbsp;", replacement = " ", x = htmlString)
  clean_string <- gsub(pattern = "nbsp", replacement = " ", x = clean_string)
  clean_string
}

#' @noRd
clean_messages <- function(text) {
  if (is.null(text)) {
    NULL
  } else {
    text %>%
      removeHTMLtags() %>%
      removeURLS() %>%
      remove_newlines() %>%
      remove_nbsp()
  }
}

Try the episomer package in your browser

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

episomer documentation built on Nov. 26, 2026, 5:07 p.m.