R/str_nobreak.R

Defines functions str_nobreak

#' Remove linebreaks and multiple spaces from string
#'
#' @param x a character vector.
#' @param replace_linebreak a scalar character to replace linebreaks with
#'
#' @return a character vector with linebreaks and multiple consecutive spaces
#'   removed
#' @export
#'
#' @md
#' @family string tools
#' @examples
#'
#' str_nobreak(
#'   "blubb,
#'   bar,
#'   foo"
#' )
#'
str_nobreak <- function(x, replace_linebreak = " "){
  assert_that(is_scalar_character(replace_linebreak))
  y <- gsub("\r?\n|\r", replace_linebreak, x)
  gsub('[ ]{2,}', ' ', y)
}
s-fleck/hammr documentation built on July 19, 2023, 9:20 p.m.