R/replace_umlaute.R

Defines functions replace_umlaute

Documented in replace_umlaute

#' Replaces german umlaute
#'
#' This function replaces german umlaute in an appropriate way to avoid
#' issues with special characters. In addition, user defined elements
#' can be replaced by an desired element, too.
#' @param names Character vector that contains german umlaute.
#' @param and Character vector.If not NULL the vector "and"
#' (default: c("-"," ")) will be replaced by the element "by"
#' @param by Character element. Set to NULL, if no replacement is desired.
#' @return Returns a character vector with replaced german umlaute.
#' @author Dennis Freuer
#' @export
#'
replace_umlaute <- function(names, and=c("-"," "), by=c("_")) {
  #sprintf("%X", as.integer(charToRaw("ß")))
  names <- gsub("\u00E4","ae",names) 
  names <- gsub("\u00FC","ue",names) 
  names <- gsub("\u00F6","oe",names) 
  names <- gsub("\u00DC","Ue",names) 
  names <- gsub("\u00C4","Ae",names) 
  names <- gsub("\u00D6","Oe",names) 
  names <- gsub("\u00DF","ss",names) 
  if(!(is.null(and) | is.null(by))){
    for(i in and){names <- gsub(i,by,names)}
  }
  return(names)
}
freuerde/puzzle documentation built on March 27, 2022, 5:30 p.m.