### ** Examples
## In principle, as not all systems have iconvlist
try(utils::head(iconvlist(), n = 50))
[1] "1026" "1046" "1047" "10646-1:1993"
[5] "437" "500" "500V1" "850"
[9] "851" "852" "855" "856"
[13] "857" "858" "860" "861"
[17] "862" "863" "864" "865"
[21] "866" "866NAV" "869" "874"
[25] "8859_1" "8859_2" "8859_3" "8859_4"
[29] "8859_5" "8859_6" "8859_7" "8859_8"
[33] "8859_9" "904" "ANSI_X3.110" "ANSI_X3.110-1983"
[37] "ANSI_X3.4" "ANSI_X3.4-1968" "ANSI_X3.4-1986" "ARABIC"
[41] "ARABIC7" "ARMSCII-8" "ARMSCII8" "ASCII"
[45] "ASMO_449" "ASMO-708" "BALTIC" "BIG-5"
[49] "BIG-FIVE" "BIG5"
## Not run:
##D ## convert from Latin-2 to UTF-8: two of the glibc iconv variants.
##D iconv(x, "ISO_8859-2", "UTF-8")
##D iconv(x, "LATIN2", "UTF-8")
## End(Not run)
## Both x below are in latin1 and will only display correctly in a
## locale that can represent and display latin1.
x <- "fa\xE7ile"
Encoding(x) <- "latin1"
x
charToRaw(xx <- iconv(x, "latin1", "UTF-8"))
iconv(x, "latin1", "ASCII") # NA
iconv(x, "latin1", "ASCII", "?") # "fa?ile"
iconv(x, "latin1", "ASCII", "") # "faile"
iconv(x, "latin1", "ASCII", "byte") # "fa<e7>ile"
iconv(xx, "UTF-8", "ASCII", "Unicode") # "fa<U+00E7>ile"
iconv(xx, "UTF-8", "ASCII", "c99") # "fa\u00E7ile"
## Extracts from old R help files (they are nowadays in UTF-8)
x <- c("Ekstr\xf8m", "J\xf6reskog", "bi\xdfchen Z\xfcrcher")
Encoding(x) <- "latin1"
x
[1] "Ekstrøm" "Jöreskog" "bißchen Zürcher"
try(iconv(x, "latin1", "ASCII//TRANSLIT")) # platform-dependent
[1] "Ekstrom" "Joreskog" "bisschen Zurcher"
iconv(x, "latin1", "ASCII", sub = "byte")
[1] "Ekstr<f8>m" "J<f6>reskog" "bi<df>chen Z<fc>rcher"
## and for Windows' 'Unicode'
str(xx <- iconv(x, "latin1", "UTF-16LE", toRaw = TRUE))
List of 3
$ : raw [1:14] 45 00 6b 00 ...
$ : raw [1:16] 4a 00 f6 00 ...
$ : raw [1:30] 62 00 69 00 ...
iconv(xx, "UTF-16LE", "UTF-8")
[1] "Ekstrøm" "Jöreskog" "bißchen Zürcher"