1
votes

I am developing an R package in RStudio (R version 3.6.1; RStudio version 1.2.1335) using roxygen2 (version 6.1.1) and am using the \insertCite{} command together with a bibtex file in order to cite references in the documentation for individual functions. I am following the instructions Inserting references in Rd and roxygen2 documentation. Everything works fine, except when I try to include a reference with accented characters. So my REFERENCES.bib file contains the following entry:

@ARTICLE{Cabcdef15,
    author={John {\c C}abcdef},
    title={A title},
    journal={Journal of Applied Stuff},
    year={2015},
    volume={81},
    number={1},
    pages={100--200},
}

The {\c C} is the LaTeX command for a C-cedilla (Ç). (I also tried \c{C} and pasting Ç directly and neither resolved the issue.)

I cited this reference in the roxygen2 preamble for my R function myfunction using \insertCite{Cabcdef15}{mypackage}. However, in the documentation output (after running devtools::document() and devtools::build(), installing the package and running library(mypackage) and ?myfunction) the citation appears in my browser (Google Chrome) as (Çabcdef 2015) rather than as (Çabcdef 2015).

Presumably this is an encoding issue. However, from what I read in the aforementioned instructions (under 4.4 Encoding of file REFERENCES.bib) this should be working, provided that I have the line Encoding: UTF-8 in the DESCRIPTION file for my R package, which I do. Hence I am stumped.

1
There's a lot of detail here: cran.r-project.org/doc/manuals/r-release/R-exts.html that might help. Search on encoding. - markhogue
Have you tried inserting the character without the encoding? Looking at some other package descriptions in Github, if an accented character shows up, it's just normal, like Ç. I think this works because of the Encoding: UTF-8 entry. Here's an example: github.com/EDiLD/esmisc/blob/master/DESCRIPTION. The example is an o with umlaut, but seems to be the same principle. - markhogue
The character "Ç" has latin1 encoding, as can be verified in R with Encoding("Ç"). I have gone through the R-exts manual material on encoding but still don't have a solution. I added @encoding UTF-8 to the roxygen2 preamble to the function but this had no effect. - Thomas Farrar
Do you have any of the package on github? - markhogue
Final suggestions, maybe try the bibentry function as suggested in the R-extensions manual section 1.9. Or ask the package develop experts here: stat.ethz.ch/mailman/listinfo/r-package-devel - markhogue

1 Answers

0
votes

I have a strong suspicion you are using a Microsoft operating system.

I have code in a roxygen2 examples block which outputs accented French characters: works fine with non-French locales on MacOS and Linux: Windows makes a mess of it. I have UTF-8 in package DESCRIPTION. For me, the obvious work-around is not to use Windows for documenting the package. UTF-8 everywhere seems to work well for me, except on Windows. The R documentation links are helpful, and, in a related post, the mighty Yihui Xie writes about this issue.

This WONTFIX R issue also hints at the root cause: Windows.

A more palatable and Windows-compatible workaround is discussed in platform specific sections in Writing R Extensions.