.REGEX_fancyquotes = sprintf("[%s]", intToUtf8(c(8220, 8221, 8216, 8217)))
.REGEX_fancydouble = sprintf("%s|%s", intToUtf8(8220), intToUtf8(8221))
.REGEX_fancysingle = sprintf("%s|%s", intToUtf8(8216), intToUtf8(8217))
#' Replace or remove fancy quotes
#'
#' @param x string or character vector
#' @param double replace fancy double quotes
#' @param single replace fancy single quotes
#' @param ... additional arguments passed to `regex` function
#'
#' @return a modified version of the input where fancy quotes have been replaced
#' @export
#' @importFrom stringr str_remove_all str_replace_all regex fixed
#'
#' @examples
#' replace_fancy("this ‘is’ a “test” it is ")
#' remove_fancy("this ‘is’ a “test” it is ")
replace_fancy <- function(x, double = TRUE, single = TRUE, ...){
if(double) x = str_replace_all( x, regex(.REGEX_fancydouble, ...), '"' )
if(single) x = str_replace_all( x, regex(.REGEX_fancysingle, ...), "'" )
return(x)
}
#' @describeIn replace_fancy remove fancy single- and double-quotes
#' @export
remove_fancy <- function(x, ...){
str_remove_all(x, regex(.REGEX_fancyquotes, ...) )
}
#' @describeIn replace_fancy remove all single and double quote characters
#' @export
remove_quotes <- function(x){
return( str_remove_all(str_remove_all( replace_fancy(x), fixed('"')), fixed("'")) )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.