Cox Tox
Cox Tox

Reputation: 691

Best way to fix encoding UTF-8 in my function's package R

I try to deal with encoding UTF-8 my R package. My R version is 3.4.4 on Windows.

My package is composed of some functions with console printing and graph who needed encoding UTF 8 (french).

I try to add this line in my R Script (at the beginning of script containing my function and in my function) but the printing is like this "Répartition de la différence"

Sys.setlocale("LC_CTYPE","french")
options(encoding = "UTF-8")

In another script, after load my package, I also add this few line but I have the same encoding problem ...

Any ideas ?

Upvotes: 3

Views: 4357

Answers (1)

chinsoon12
chinsoon12

Reputation: 25225

You can add a line specifying Encoding: UTF-8 in your DESCRIPTION file.

See https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Character-encoding-issues

If the DESCRIPTION file is not entirely in ASCII it should contain an ‘Encoding’ field specifying an encoding. This is used as the encoding of the DESCRIPTION file itself and of the R and NAMESPACE files, and as the default encoding of .Rd files. The examples are assumed to be in this encoding when running R CMD check, and it is used for the encoding of the CITATION file. Only encoding names latin1, latin2 and UTF-8 are known to be portable. (Do not specify an encoding unless one is actually needed: doing so makes the package less portable. If a package has a specified encoding, you should run R CMD build etc in a locale using that encoding.)

Please let me know if it solves your issue.

Upvotes: 4

Related Questions