[R-pkg-devel] UTF-8 and raw strings in package code

Mark Bravington m@rk|nr @end|ng |rom @ummer|n@outh@net
Sat Nov 29 11:55:52 CET 2025


Hi--- My package 'lyxport' has R code with several raw strings (see ?Quotes) which contain UTF-8 characters (FWIW: in order to deal with wacky legacy Latex characters). For example, one of the strings is:

  converto <- r"--{
      Ä   \"A ä   \"a Á   \'A á   \'a Ȧ   \.A ȧ   \.a Ā   \=A
      ā   \=a    \^A â   \^a À   \`A à   \`a Ą   \k{A} ą   \k{a}
<snipped>
      Ŋ   {\NG} Ø   {\O}  ø   {\o}  œ   {\oe} Œ   {\OE} ß   {\ss} þ   {\th}
      Þ   {\TH}
    }--"

RCMD CHECK is not happy, and gives a Warning:

"Portable packages must use only ASCII characters in their R code and NAMESPACE directives, except perhaps in comments. Use \uxxxx escapes for other characters."

and indeed that is as stated in "Writing R extensions", section 1.1.5 ("Package subdirectories") and section 1.6.3, "Encoding issues".

But I wonder if this is still sensible now that

(i) R has raw strings (since ~R 4.0);
(ii) the DESCRIPTION file explicitly says "Encoding: UTF-8"; and 
(iii) R >= 4.2 pretty much now enforces UTF-8 in Windows (and UTF-8 could even be a "requirement" of this package, if that helped).

With "normal" strings then maybe the \uxxxx thing is reasonable; but shouldn't the contents of raw strings be exempt? You can't put \uxxxx into a raw string, for obvious reasons...

cheers
Mark


PS Of course, there are ways around the Warning (eg storing the strings as files elsewhere in the package, and reading those files during the code) but they are tedious, harder to maintain, and reduce clarity (imagine using \uxxxx in the above!). Since I don't particularly care whether the package goes on CRAN or not (it's living quite happily in R-universe), I've no plans to change my code, but I would prefer to avoid Warnings that then have to be explained to would-be users. And I am probably not the only person affected.

PPS The package has been working fine on Windows, Macs, and Linux.



More information about the R-package-devel mailing list