replace_non_ascii: Replace Common Non-ASCII Characters

Description Usage Arguments Value Examples

Description

replace_non_ascii - Replaces common non-ASCII characters.

replace_curly_quote - Replaces curly single and double quotes. This provides a subset of functionality found in replace_non_ascii specific to quotes.

Usage

1
2
3
replace_non_ascii(x, replacement = "", remove.nonconverted = TRUE, ...)

replace_curly_quote(x, ...)

Arguments

x

The text variable.

replacement

Character string equal in length to pattern or of length one which are a replacement for matched pattern.

remove.nonconverted

logical. If TRUE unmapped encodings are deleted from the string.

...

ignored.

Value

Returns a text variable (character sting) with non-ASCII characters replaced.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x <- c(
    "Hello World", "6 Ekstr\xf8m", "J\xf6reskog", "bi\xdfchen Z\xfcrcher",
    'This is a \xA9 but not a \xAE', '6 \xF7 2 = 3', 
    'fractions \xBC, \xBD, \xBE', 'cows go \xB5', '30\xA2'
)
Encoding(x) <- "latin1"
x

replace_non_ascii(x)
replace_non_ascii(x, remove.nonconverted = FALSE)

z <- '\x95He said, \x93Gross, I am going to!\x94'
Encoding(z) <- "latin1"
z

replace_curly_quote(z)
replace_non_ascii(z)

Example output

[1] "Hello World"                   "6 Ekstr<f8>m"                 
[3] "J<f6>reskog"                   "bi<df>chen Z<fc>rcher"        
[5] "This is a <a9> but not a <ae>" "6 <f7> 2 = 3"                 
[7] "fractions <bc>, <bd>, <be>"    "cows go <b5>"                 
[9] "30<a2>"                       
[1] "Hello World"                 "6 Ekstrom"                  
[3] "Joreskog"                    "bisschen Zurcher"           
[5] "This is a (C) but not a (R)" "6 / 2 = 3"                  
[7] "fractions 1/4, 1/2, 3/4"     "cows go mu"                 
[9] "30 cent"                    
[1] "Hello World"                 "6 Ekstrom"                  
[3] "Joreskog"                    "bisschen Zurcher"           
[5] "This is a (C) but not a (R)" "6 / 2 = 3"                  
[7] "fractions  1/4,  1/2,  3/4"  "cows go <c2> mu "           
[9] "30<c2> cent "               
[1] "<95>He said, <93>Gross, I am going to!<94>"
[1] "<95>He said, \"Gross, I am going to!\""
[1] "He said, \"Gross, I am going to!\""

textclean documentation built on May 2, 2019, 7:22 a.m.