R/allpautils_names.R

Defines functions allpautils_names

Documented in allpautils_names

#' Remove accents and hyphens in character vector
#'
#' @description This function will allow you to remove accents, hyphens and
#'   any strange characters that come from the UTF-8 encoding, with the intention
#'   of working with standardized names or texts.Review:
#'   https://cran.r-project.org/web/packages/MazamaSpatialUtils/vignettes/MazamaSpatialUtils.html
#'
#' @param string Characters vector
#'
#' @examples
#' library(innovar)
#' string <- c("PerĂº", "Estados Unidos")
#' allpautils_names(string)
#'
#' @export allpautils_names
allpautils_names <- function(string) {

  string <- gsub(pattern = "_",
                 replacement = " ",
                 x = gsub(pattern = "-",
                          replacement = " ",
                          x = iconv(string,
                                    from="UTF-8",
                                    to="ASCII//TRANSLIT"),
                          fixed=TRUE),
                 fixed=TRUE)

  return(string)
}
healthinnovation/lis documentation built on June 19, 2024, 6:06 a.m.