Title: | Rcpp Example of Using Iconv Offered by R |
---|---|
Description: | Character conversion via the 'iconv' library is used by R itself, and can be accessed from compiled code relying on one standard header exported by R. This package illustrates this usage by building on and extending an earlier example in a blog post at <https://fishandwhistle.net/post/2021/using-rs-cross-platform-iconv-wrapper-from-cpp11/>. Rcpp is used only for its convenience of seamlessly building the package, and converting between character variable at the R and C++ levels. |
Authors: | Dirk Eddelbuettel |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.1 |
Built: | 2024-12-04 03:40:33 UTC |
Source: | https://github.com/eddelbuettel/rcppiconvexample |
Character conversion via the 'iconv' library is used by R itself, and can be accessed from compiled code relying on one standard header exported by R. This package illustrates this usage by building on and extending an earlier example in a blog post at <https://fishandwhistle.net/post/2021/using-rs-cross-platform-iconv-wrapper-from-cpp11/>. Rcpp is used only for its convenience of seamlessly building the package, and converting between character variable at the R and C++ levels.
Index of help topics:
RcppIconvExample-package Rcpp Example of Using Iconv Offered by R read_file Read an Enconded File, Optionally Converting to Another Encoding
Dirk Eddelbuettel <[email protected]>
Dirk Eddelbuettel
This function relies on the 'iconv' facility available with R. Having 'iconv' is optional but
likely for most builds of R; see capabilities("iconv")
to verify. Also note that
'iconv', while portable, does not guarantee identical results across implementations and
operating systems.
read_file(filename, encoding = "")
read_file(filename, encoding = "")
filename |
[string] A filename |
encoding |
[string, optional] An encoding. If present, file content is converted to the given encoding; if missing (as indicated by the default empty string) no conversion is made. |
A string
https://fishandwhistle.net/post/2021/using-rs-cross-platform-iconv-wrapper-from-cpp11/
## example file from package 'uchardet' encoding as windows-1252 win1252file <- system.file("rawdata", "windows-1252.txt", package="RcppIconvExample") win1252txt <- read_file(win1252file, "windows-1252") utf8file <- system.file("rawdata", "utf8.txt", package="RcppIconvExample") utf8txt <- read_file(utf8file, "UTF-8") stopifnot(substr(win1252txt, 1, 62) == substr(utf8txt, 1, 62)) cat(win1252txt)
## example file from package 'uchardet' encoding as windows-1252 win1252file <- system.file("rawdata", "windows-1252.txt", package="RcppIconvExample") win1252txt <- read_file(win1252file, "windows-1252") utf8file <- system.file("rawdata", "utf8.txt", package="RcppIconvExample") utf8txt <- read_file(utf8file, "UTF-8") stopifnot(substr(win1252txt, 1, 62) == substr(utf8txt, 1, 62)) cat(win1252txt)