[Rd] How to print UTF-8 encoded strings from a C routine to R's output?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Sep 5 12:31:51 CEST 2016


On 05/09/2016 12:40 AM, Lixin Gong wrote:
> Dear R experts,
>
> It seems that Rprintf has to be used to print from a C routine to guarantee
> to write to R’s output according to
> https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Printing.
>
> However if a string is UTF-8 encoded, non-ASCII characters (e.g., the
> infinity symbol http://www.fileformat.info/info/unicode/char/221e/index.htm)
> are misprinted.
> Is this an unsupported feature or is there a workaround for this limitation?

If you are working in a UTF-8 locale (as on most Unix-like systems), you 
should be fine.  If not (as is normal on Windows), you'll need to 
translate the string to the local encoding.  The Writing R Extensions 
manual section 6.11 tells you how to do the re-encoding.

Duncan Murdoch



More information about the R-devel mailing list